From dddc5cc2fa3f0285e1bb5feafddf8ad1ffca5322 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Wed, 25 Sep 2024 14:29:56 +0800 Subject: [PATCH] fix: support two formats of hopi worker id --- lib/routes/hpoi/utils.ts | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/routes/hpoi/utils.ts b/lib/routes/hpoi/utils.ts index 100d9c408..87561fb69 100644 --- a/lib/routes/hpoi/utils.ts +++ b/lib/routes/hpoi/utils.ts @@ -12,6 +12,10 @@ const MAPs = { url: `${host}/hobby/all?order={order}&r18=-1&works={id}`, title: '作品周边', }, + overview: { + url: `${host}/works/{id}`, + title: '周边总览', + }, all: { url: `${host}/hobby/all?order={order}&r18=-1`, title: '全部周边', @@ -19,15 +23,44 @@ const MAPs = { }; const ProcessFeed = async (type, id, order) => { - const link = MAPs[type].url.replace(/{id}/, id).replace(/{order}/, order || 'add'); - const response = await got({ + let link = MAPs[type].url.replace(/{id}/, id).replace(/{order}/, order || 'add'); + let response = await got({ method: 'get', url: link, headers: { Referer: host, }, }); - const $ = load(response.data); + let $ = load(response.data); + + if (type === 'work') { + const overviewLink = MAPs.overview.url.replace(/{id}/, id); + const overviewResponse = await got({ + method: 'get', + url: overviewLink, + headers: { + Referer: host, + }, + }); + const $overview = load(overviewResponse.data); + + const moreLink = $overview('.company-ibox a.hpoi-btn-border.hpoi-btn-more').attr('href'); + if (moreLink) { + const worksId = moreLink.match(/modal\/taobao\/more\/(\d+)/)?.[1]; + if (worksId) { + link = `${host}/hobby/all?order=${order || 'add'}&r18=-1&works=${worksId}`; + response = await got({ + method: 'get', + url: link, + headers: { + Referer: host, + }, + }); + $ = load(response.data); + } + } + } + return { title: `Hpoi 手办维基 - ${MAPs[type].title}${id ? ` ${id}` : ''}`, link,