From 8befd48d0b5205bc9327bdf22dec7aa701ec8c03 Mon Sep 17 00:00:00 2001 From: quiniapiezoelectricity <73748843+quiniapiezoelectricity@users.noreply.github.com> Date: Wed, 5 Feb 2025 23:15:01 +0800 Subject: [PATCH] fix(route/theinitium): fix app route user-agent issues (#18279) --- lib/routes/theinitium/app.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/routes/theinitium/app.ts b/lib/routes/theinitium/app.ts index b176d15e3..5f7daf2b0 100644 --- a/lib/routes/theinitium/app.ts +++ b/lib/routes/theinitium/app.ts @@ -73,24 +73,23 @@ async function handler(ctx) { const category = ctx.req.param('category') ?? 'latest_sc'; const __dirname = getCurrentPath(import.meta.url); const baseUrl = 'https://app.theinitium.com/'; + const userAgent = 'PugpigBolt v4.1.8 (iPhone, iOS 18.2.1) on phone (model iPhone15,2)'; - const feeds = await cache.tryGet( - new URL('timelines.json', baseUrl).href, - async () => - await got({ - method: 'get', - url: new URL('timelines.json', baseUrl).href, - }), - config.cache.routeExpire, - false - ); + async function getUA(url: string) { + return await got({ + method: 'get', + url, + headers: { + 'User-Agent': userAgent, + }, + }); + } + + const feeds = await cache.tryGet(new URL('timelines.json', baseUrl).href, async () => await getUA(new URL('timelines.json', baseUrl).href), config.cache.routeExpire, false); const metadata = feeds.data.timelines.find((timeline) => timeline.id === category); - const response = await got({ - method: 'get', - url: new URL(metadata.feed, baseUrl).href, - }); + const response = await getUA(new URL(metadata.feed, baseUrl).href); const feed = response.data.stories.filter((item) => item.type === 'article'); @@ -113,7 +112,7 @@ async function handler(ctx) { } } item.category = [...new Set(item.category)]; - const response = await got(new URL(item.url, baseUrl).href); + const response = await getUA(new URL(item.url, baseUrl).href); const $ = load(response.data); // resolve relative links with app.theinitium.com // code from @/middleware/paratmeter.ts