mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
Removing sensitive logs and revert back to false redis cache.
Some checks failed
Run_Svelte_Unit_on_PRs / test (push) Has been cancelled
Some checks failed
Run_Svelte_Unit_on_PRs / test (push) Has been cancelled
This commit is contained in:
parent
242ee943b5
commit
3f4e9eb5ff
2 changed files with 16 additions and 26 deletions
2
.github/workflows/svelte_integration.yml
vendored
2
.github/workflows/svelte_integration.yml
vendored
|
|
@ -46,7 +46,7 @@ jobs:
|
|||
PUBLIC_UMAMI_URL: ${{ secrets.PUBLIC_UMAMI_URL }}
|
||||
PUBLIC_UMAMI_ID: ${{ secrets.PUBLIC_UMAMI_ID }}
|
||||
PAGE_SIZE: ${{ secrets.PAGE_SIZE }}
|
||||
USE_REDIS_CACHE: ${{ secrets.USE_REDIS_CACHE }}
|
||||
USE_REDIS_CACHE: 'false'
|
||||
REDIS_URI: ${{ secrets.REDIS_URI }}
|
||||
run: pnpm test:integration
|
||||
- uses: actions/upload-artifact@v4
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ import type { Article, ArticlePageLoad, WallabagArticle } from '$lib/types/artic
|
|||
import { ArticleTag } from '$lib/types/articleTag';
|
||||
import type { PageQuery } from '../types/pageQuery';
|
||||
|
||||
const base: string = WALLABAG_URL;
|
||||
// Normalize Wallabag base URL and derive endpoints robustly
|
||||
const wallabagBase = new URL(WALLABAG_URL);
|
||||
const tokenUrl = new URL('/oauth/v2/token', wallabagBase).toString();
|
||||
const entriesUrl = new URL('/api/entries.json', wallabagBase).toString();
|
||||
|
||||
// Retry helper with exponential backoff
|
||||
async function retryWithBackoff<T>(fn: () => Promise<T>, maxRetries = 3, baseDelay = 500): Promise<T> {
|
||||
|
|
@ -66,21 +69,15 @@ export async function fetchArticlesApi(_method: string, _resource: string, query
|
|||
});
|
||||
|
||||
if (USE_REDIS_CACHE === 'true') {
|
||||
console.log('Using redis cache');
|
||||
const cacheKey = entriesQueryParams.toString();
|
||||
console.log(`Cache key: ${cacheKey}`);
|
||||
const cached = await redis.get(cacheKey);
|
||||
|
||||
if (cached) {
|
||||
console.log('Cache hit!');
|
||||
// Cache hit, return cached payload with TTL-derived cache-control
|
||||
const response = JSON.parse(cached);
|
||||
const ttl = await redis.ttl(cacheKey);
|
||||
|
||||
console.log(`Returning cached response for page ${pageQuery.page} with ttl of ${ttl} seconds`);
|
||||
console.log(`Response: ${JSON.stringify(response)}`);
|
||||
return { ...response, cacheControl: `max-age=${ttl}` };
|
||||
}
|
||||
console.log(`Cache miss for page ${pageQuery.page}, fetching from API`);
|
||||
}
|
||||
|
||||
const authBody = {
|
||||
|
|
@ -91,10 +88,9 @@ export async function fetchArticlesApi(_method: string, _resource: string, query
|
|||
password: WALLABAG_PASSWORD,
|
||||
};
|
||||
|
||||
console.log(`Auth body: ${JSON.stringify(authBody)}`);
|
||||
|
||||
const auth = await retryWithBackoff(async () => {
|
||||
const authResponse = await fetch(`${base}/oauth/v2/token`, {
|
||||
// Authenticate to Wallabag
|
||||
const authResponse = await fetch(tokenUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams(authBody),
|
||||
|
|
@ -108,21 +104,21 @@ export async function fetchArticlesApi(_method: string, _resource: string, query
|
|||
return await authResponse.json();
|
||||
});
|
||||
|
||||
console.log(`Got auth response: ${JSON.stringify(auth)}`);
|
||||
|
||||
const { wallabagResponse, cacheControl } = await retryWithBackoff(async () => {
|
||||
const pageResponse = await fetch(`${WALLABAG_URL}/api/entries.json?${entriesQueryParams}`, {
|
||||
const requestUrl = `${entriesUrl}?${entriesQueryParams}`;
|
||||
// console.debug(`Fetching Wallabag entries: ${requestUrl}`);
|
||||
const pageResponse = await fetch(requestUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${auth.access_token}`,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
signal: AbortSignal.timeout(15000), // 15 second timeout
|
||||
});
|
||||
|
||||
console.log('pageResponse', pageResponse);
|
||||
|
||||
if (!pageResponse.ok) {
|
||||
console.log('pageResponse not ok', pageResponse);
|
||||
// Log status only to avoid leaking headers/body
|
||||
console.warn(`Wallabag entries request failed: ${pageResponse.status} ${pageResponse.statusText}`);
|
||||
throw new Error(`API request failed: ${pageResponse.status} ${pageResponse.statusText}`);
|
||||
}
|
||||
|
||||
|
|
@ -131,15 +127,11 @@ export async function fetchArticlesApi(_method: string, _resource: string, query
|
|||
|
||||
return { wallabagResponse, cacheControl };
|
||||
});
|
||||
console.log('wallabagResponse', JSON.stringify(wallabagResponse));
|
||||
const { _embedded: favoriteArticles, page, pages, total, limit } = wallabagResponse;
|
||||
const articles: Article[] = [];
|
||||
|
||||
console.log('favoriteArticles', JSON.stringify(favoriteArticles));
|
||||
console.log('pages', pages);
|
||||
console.log('page', page);
|
||||
console.log('total', total);
|
||||
console.log('limit', limit);
|
||||
// Minimal, non-sensitive diagnostics
|
||||
console.info(`Wallabag entries: page=${page} pages=${pages} total=${total} limit=${limit}`);
|
||||
|
||||
for (const article of favoriteArticles.items as WallabagArticle[]) {
|
||||
const rawTags = article?.tags?.map((tag) => tag.slug);
|
||||
|
|
@ -169,8 +161,6 @@ export async function fetchArticlesApi(_method: string, _resource: string, query
|
|||
cacheControl,
|
||||
};
|
||||
|
||||
console.log('Response data from API: ', JSON.stringify(responseData));
|
||||
|
||||
if (USE_REDIS_CACHE === 'true' && responseData?.articles?.length > 0) {
|
||||
const cacheKey = entriesQueryParams.toString();
|
||||
console.log(`Storing in cache with key: ${cacheKey} for page ${page}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue