diff --git a/about/scraping_line_today_home.md b/about/scraping_line_today_home.md index c90a0ef..8d08be5 100644 --- a/about/scraping_line_today_home.md +++ b/about/scraping_line_today_home.md @@ -5,7 +5,7 @@ This took me some time, but they use a fancy system for pulling news data. ## Endpoint on news.yuanhau.com aka this repo (Cached results) -### /api/home/uuid_lt/feed?query=${query} +### /api/home/lt?query=${query} Fetches the uuid and returns back with the news ## Main endpoint diff --git a/nuxt.config.ts b/nuxt.config.ts index ac7ab40..fc2285a 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -19,7 +19,7 @@ export default defineNuxtConfig({ }, "/api/cached/**": { swr: 3600 }, "/api/news/get": { swr: 3600 }, - "/api/home/uuid_lt": { swr: 3600 }, + "/api/home/lt": { swr: 3600 }, }, css: ["~/styles/main.css"], diff --git a/server/api/home/uuid_lt/index.ts b/server/api/home/lt.ts similarity index 94% rename from server/api/home/uuid_lt/index.ts rename to server/api/home/lt.ts index 61ac197..09b13f5 100644 --- a/server/api/home/uuid_lt/index.ts +++ b/server/api/home/lt.ts @@ -10,7 +10,10 @@ async function getUUID(orgtype: string) { const type = orgtype.toLowerCase(); if (cache[type] && Date.now() - cache[type].timestamp < CACHE_DURATION) { console.log("Serving from cache for type:", type); - return cache[type].data; + return { + ...cache[type].data, + cached: true, + }; } try { @@ -60,7 +63,7 @@ function filterUUIDs(ids: string[]): string[] { } function filter2(ids: string[]): string[] { - const pattern = /.*:[a-zA-Z0-9]{24}/g; + const pattern = /news_cat:[a-zA-Z0-9]{24}/g; return ids.filter((id) => pattern.test(id)); } @@ -113,11 +116,8 @@ export default defineEventHandler(async (event) => { const fillll = filter2(diffFormat); const cconaa: any[] = await Promise.all( fillll.map(async (key) => { - if (key.includes("news_cat")) { - const data = await tryToPullDataNUUID(key); - return data; - } else { - } + const data = await tryToPullDataNUUID(key); + return data; }), ).then((ans) => ans.flat()); return {