docs: add FANTIA_COOKIE (#21755)
* docs: add FANTIA_COOKIE * fix(user): handle optional fanClub.comment in description
This commit is contained in:
parent
e081128355
commit
0bed8a993d
|
|
@ -81,7 +81,13 @@ export const route: Route = {
|
|||
keyword: 'Keyword, empty by default',
|
||||
},
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'FANTIA_COOKIE',
|
||||
optional: true,
|
||||
description: 'The `cookie` after login can be obtained by viewing the request header in the console, If not filled in will cause some posts that require login to read to get exceptions',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { config } from '@/config';
|
|||
import type { Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
|
|
@ -12,7 +12,13 @@ export const route: Route = {
|
|||
example: '/fantia/user/3498',
|
||||
parameters: { id: 'User id, can be found in user profile URL' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'FANTIA_COOKIE',
|
||||
optional: true,
|
||||
description: 'The `cookie` after login can be obtained by viewing the request header in the console, If not filled in will cause some posts that require login to read to get exceptions',
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
|
|
@ -34,36 +40,32 @@ async function handler(ctx) {
|
|||
const rootUrl = 'https://fantia.jp';
|
||||
const userUrl = `${rootUrl}/api/v1/fanclubs/${ctx.req.param('id')}`;
|
||||
|
||||
const initalResponse = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
const initalResponse = await ofetch(rootUrl, {
|
||||
headers: {
|
||||
Cookie: config.fantia.cookies ?? '',
|
||||
},
|
||||
});
|
||||
|
||||
const csrfToken = initalResponse.data.match(/name="csrf-token" content="(.*?)"\s?\/>/)[1];
|
||||
const csrfToken = initalResponse.match(/name="csrf-token" content="(.*?)"\s?\/>/)[1];
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: userUrl,
|
||||
const response = await ofetch(userUrl, {
|
||||
headers: {
|
||||
Cookie: config.fantia.cookies ?? '',
|
||||
},
|
||||
});
|
||||
|
||||
const list = response.data.fanclub.recent_posts.map((item) => ({
|
||||
const fanClub = response.fanclub;
|
||||
|
||||
const list = response.fanclub.recent_posts.map((item) => ({
|
||||
title: item.title,
|
||||
link: `${rootUrl}/api/v1/posts/${item.id}`,
|
||||
description: `<p>${item.comment}</p>`,
|
||||
description: item.comment ? `<p>${item.comment}</p>` : '',
|
||||
pubDate: parseDate(item.posted_at),
|
||||
}));
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
const contentResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
const contentResponse = await ofetch(item.link, {
|
||||
headers: {
|
||||
Cookie: config.fantia.cookies ?? '',
|
||||
'X-CSRF-Token': csrfToken,
|
||||
|
|
@ -73,7 +75,7 @@ async function handler(ctx) {
|
|||
},
|
||||
});
|
||||
item.link = item.link.replace('api/v1/', '');
|
||||
item.description += `<img src="${contentResponse.data.post?.thumb?.large ?? contentResponse.data.post.thumb_micro}">`;
|
||||
item.description += `<img src="${contentResponse.post?.thumb?.original ?? contentResponse.post.thumb_micro}">`;
|
||||
|
||||
return item;
|
||||
})
|
||||
|
|
@ -81,8 +83,10 @@ async function handler(ctx) {
|
|||
);
|
||||
|
||||
return {
|
||||
title: `Fantia - ${response.data.fanclub.fanclub_name_with_creator_name}`,
|
||||
title: `Fantia - ${fanClub.fanclub_name_with_creator_name}`,
|
||||
description: fanClub.comment?.replaceAll('\r\n', ' ')?.trim(),
|
||||
link: `${rootUrl}/fanclubs/${ctx.req.param('id')}`,
|
||||
image: fanClub.icon.original ?? fanClub.icon.main,
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue