Update slug stuff.

This commit is contained in:
吳元皓 2025-05-21 11:58:13 +08:00
parent 004028d7b5
commit c8429ee1a3
3 changed files with 42 additions and 6 deletions

View File

@ -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.

View File

@ -0,0 +1,5 @@
<template>
<div class="justify-center align-center text-center">
<div></div>
</div>
</template>

View File

@ -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 {