mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 23:42:40 +08:00
fix(route/lofter): fix Lofter tag route requiring cookie (#19548)
This commit is contained in:
@@ -220,6 +220,9 @@ export type Config = {
|
||||
lightnovel: {
|
||||
cookie?: string;
|
||||
};
|
||||
lofter: {
|
||||
cookies?: string;
|
||||
};
|
||||
lorientlejour: {
|
||||
token?: string;
|
||||
username?: string;
|
||||
@@ -683,6 +686,9 @@ const calculateValue = () => {
|
||||
lightnovel: {
|
||||
cookie: envs.SECURITY_KEY,
|
||||
},
|
||||
lofter: {
|
||||
cookies: envs.LOFTER_COOKIE,
|
||||
},
|
||||
lorientlejour: {
|
||||
token: envs.LORIENTLEJOUR_TOKEN,
|
||||
username: envs.LORIENTLEJOUR_USERNAME,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { config } from '@/config';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/tag/:name?/:type?',
|
||||
@@ -10,7 +12,16 @@ export const route: Route = {
|
||||
example: '/lofter/tag/cosplay/date',
|
||||
parameters: { name: 'tag name, such as `名侦探柯南`, `摄影` by default', type: 'ranking type, see below, new by default' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'LOFTER_COOKIE',
|
||||
description: `LOFTER_COOKIE: 用于搜索标签相关内容,获取方式:
|
||||
1. 登录 Lofter 并搜索任一标签,进入页面 https://www.lofter.com/tag/*
|
||||
2. 打开控制台,切换到 Network 面板,刷新
|
||||
3. 点击 TagBean.seach.dwr 请求,找到 Cookie
|
||||
4. 获取最新标签内容只要求 \`LOFTER_SESS\` 开始的字段`,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
@@ -20,7 +31,11 @@ export const route: Route = {
|
||||
name: 'Tag',
|
||||
maintainers: ['hoilc', 'nczitzk', 'LucunJi'],
|
||||
handler,
|
||||
description: `| new | date | week | month | total |
|
||||
description: `::: warning
|
||||
搜索标签下的最新内容需要 Lofter 登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
|
||||
:::
|
||||
|
||||
| new | date | week | month | total |
|
||||
| ---- | ---- | ---- | ----- | ----- |
|
||||
| 最新 | 日榜 | 周榜 | 月榜 | 总榜 |`,
|
||||
};
|
||||
@@ -33,7 +48,12 @@ async function handler(ctx) {
|
||||
|
||||
const rootUrl = 'https://www.lofter.com';
|
||||
const linkUrl = `${rootUrl}/tag/${name}/${type}`;
|
||||
const apiUrl = `${rootUrl}/dwr/call/plaincall/TagBean.getCommonTagExcellentAuthors.dwr`;
|
||||
const apiUrl = `${rootUrl}/dwr/call/plaincall/TagBean.search.dwr`;
|
||||
|
||||
const cookie = config.lofter.cookies;
|
||||
if (cookie === undefined) {
|
||||
throw new ConfigNotFoundError('Lofter 用户登录后的 Cookie 值');
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'post',
|
||||
@@ -56,6 +76,10 @@ async function handler(ctx) {
|
||||
'c0-param8': 'number:0',
|
||||
batchId: 493053,
|
||||
}),
|
||||
headers: {
|
||||
Referer: `https://www.lofter.com/tag/${encodeURI(name)}`,
|
||||
Cookie: cookie,
|
||||
},
|
||||
});
|
||||
|
||||
const dom = new JSDOM(
|
||||
|
||||
Reference in New Issue
Block a user