From c8429ee1a3dbdd6eda2bd2eceb67e950ce42960d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E5=85=83=E7=9A=93?= Date: Wed, 21 May 2025 11:58:13 +0800 Subject: [PATCH] Update slug stuff. --- about/scraping_line_today_home.md | 2 +- components/app/windows/news.vue | 5 +++ .../home/{lt/[slug].ts => uuid_lt/feed.ts} | 41 ++++++++++++++++--- 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 components/app/windows/news.vue rename server/api/home/{lt/[slug].ts => uuid_lt/feed.ts} (68%) diff --git a/about/scraping_line_today_home.md b/about/scraping_line_today_home.md index f6d3872..46d8cbe 100644 --- a/about/scraping_line_today_home.md +++ b/about/scraping_line_today_home.md @@ -45,7 +45,7 @@ We can ignore everything else, other than the strange UUID in the json. Well, th Here is the fancy URL: `https://today.line.me/api/v6/listings/{the-uuid-you-got-in-the-listings-json-file}/?country=tw&offset=0&length=24` -This api can be used for fetching the news from them, however, there is an issue, the max length is only just 24 (yes, I tried it only can return 24 when requesting for 1000) +This api can be used for fetching the news from them, however, there is an issue, the max length is only just 24 (yes, I tried it only can return 27* when requesting for 1000) And viewing the JSON, oh would you look at that. diff --git a/components/app/windows/news.vue b/components/app/windows/news.vue new file mode 100644 index 0000000..c689e02 --- /dev/null +++ b/components/app/windows/news.vue @@ -0,0 +1,5 @@ + diff --git a/server/api/home/lt/[slug].ts b/server/api/home/uuid_lt/feed.ts similarity index 68% rename from server/api/home/lt/[slug].ts rename to server/api/home/uuid_lt/feed.ts index 35bd4f1..07b5018 100644 --- a/server/api/home/lt/[slug].ts +++ b/server/api/home/uuid_lt/feed.ts @@ -59,15 +59,46 @@ function filterUUIDs(ids: string[]): string[] { return ids.filter((id) => uuidPattern.test(id)); } +function filter2(ids: string[]): string[] { + const pattern = /.*:[a-zA-Z0-9]{24}/g; + return ids.filter((id) => pattern.test(id)); +} + +async function tryToPullDataUUID(uuid: string) { + const buildUrl = + "https://today.line.me/api/v6/listings/" + + uuid + + "?country=tw&offset=0&length=27"; + const req = await fetch(buildUrl); + const res = await req.json(); + return res; +} + export default defineEventHandler(async (event) => { try { + const query = getQuery(event); + if (!query.query) { + return { + error: "NOT_A_QUERY", + }; + } const data = await getUUID(String(query.query)); const validUUIDs = filterUUIDs(data || []); - const slug = getRouterParam(event, "slug"); - const urlBuild = "/api/home/uuid_lt/action?query=" + String(slug.trim()); - const articleArray = []; - const { data: res } = await useFetch(urlBuild); - return res; + const diffFormat = []; + data.forEach((key) => { + if (validUUIDs.includes(key)) { + return; + } else { + diffFormat.push(key); + } + }); + const returnData = []; + validUUIDs.forEach(async (key) => { + const data = await tryToPullDataUUID(key); + returnData.push(data); + }); + const fillll = filter2(diffFormat); + return { valid: validUUIDs, maybe: fillll, returnData: returnData }; } catch (e) { console.log(e); return {