From 9a56bb8803a1bf045fd603508b3e51356cfc2805 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 16 Jan 2023 21:10:13 +0800 Subject: [PATCH] fix(route): pixiv novels (#11629) --- lib/v2/pixiv/novels.js | 55 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/v2/pixiv/novels.js b/lib/v2/pixiv/novels.js index 44567f3b2..4ed242a6c 100644 --- a/lib/v2/pixiv/novels.js +++ b/lib/v2/pixiv/novels.js @@ -4,32 +4,41 @@ const baseUrl = 'https://www.pixiv.net'; module.exports = async (ctx) => { const { id } = ctx.params; - const { data } = await got(`${baseUrl}/ajax/user/${id}/profile/all`); + const url = `${baseUrl}/users/${id}/novels`; + const { data: allData } = await got(`${baseUrl}/ajax/user/${id}/profile/all`, { + headers: { + referer: url, + }, + }); - const items = [ - ...data.body.novelSeries.map((item) => ({ - title: item.title, - description: item.caption, - link: `https://www.pixiv.net/novel/series/${item.id}`, - author: item.userName, - pubDate: parseDate(item.createDate), - updated: parseDate(item.updateDate), - category: item.tags, - })), - ...data.body.pickup.map((item) => ({ - title: item.title, - description: item.description, - link: item.contentUrl, - author: item.userName, - pubDate: parseDate(item.createDate), - updated: parseDate(item.updateDate), - category: item.tags, - })), - ]; + const novels = Object.keys(allData.body.novels); + const searchParams = new URLSearchParams(); + novels.forEach((novel) => { + searchParams.append('ids[]', novel); + }); + + const { data } = await got(`${baseUrl}/ajax/user/${id}/profile/novels`, { + headers: { + referer: url, + }, + searchParams, + }); + + const items = Object.values(data.body.works).map((item) => ({ + title: item.seriesTitle || item.title, + description: item.description || item.title, + link: `${baseUrl}/novel/series/${item.id}`, + author: item.userName, + pubDate: parseDate(item.createDate), + updated: parseDate(item.updateDate), + category: item.tags, + })); ctx.state.data = { - title: `${data.body.novelSeries[0].userName || data.body.pickup[0].userName} 的小说`, - link: `${baseUrl}/users/${id}/novels`, + title: data.body.extraData.meta.title, + description: data.body.extraData.meta.ogp.description, + image: Object.values(data.body.works)[0].profileImageUrl, + link: url, item: items, }; };