Skip to content

Commit

Permalink
fix: support two formats of hopi worker id
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Sep 25, 2024
1 parent f9e891b commit dddc5cc
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions lib/routes/hpoi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,55 @@ 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: '全部周边',
},
};

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,
Expand Down

0 comments on commit dddc5cc

Please sign in to comment.