feat: add javdb session config and cookieJar to fakeGot (#14782)
* feat: add javdb session config * fix: Return data instead of setting ctx.set in JavDB routes * docs: Add JavDB login instructions to config.md * docs: Add note about javdb session validity in config.md * fix: Return data instead of setting ctx.set in JavDB routes * fix: Update route path in javdb index.ts Remove '/:category?/:sort?/:filter?', it will cause other module routes to be inaccessible * chore: Remove unused cookie variable in ProcessItems function * chore: Unnecessary changes * chore: Add JAVDB sessions in alphabetical order. * docs: Add JAVDB sessions in alphabetical order. * feat: Add support for passing cookies in headers * test: Add cookieJar test to got.test.ts * Update lib/utils/got.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * feat: Update JavDB routes to include optional JAVDB_SESSION in requireConfig --------- Co-authored-by: zhaoyi.wu <zhaoyi.wu@amh-group.com>
This commit is contained in:
parent
7c76f385a3
commit
a51cc049bf
|
|
@ -166,6 +166,9 @@ export type Config = {
|
|||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
javdb: {
|
||||
session?: string;
|
||||
};
|
||||
lastfm: {
|
||||
api_key?: string;
|
||||
};
|
||||
|
|
@ -508,6 +511,9 @@ const calculateValue = () => {
|
|||
username: envs.IWARA_USERNAME,
|
||||
password: envs.IWARA_PASSWORD,
|
||||
},
|
||||
javdb: {
|
||||
session: envs.JAVDB_SESSION,
|
||||
},
|
||||
lastfm: {
|
||||
api_key: envs.LASTFM_API_KEY,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/actors/R2Vg',
|
||||
parameters: { id: '编号,可在演员页 URL 中找到', filter: '过滤,见下表,默认为 `全部`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
@ -46,6 +52,5 @@ async function handler(ctx) {
|
|||
};
|
||||
|
||||
const title = `JavDB${filters[filter] === '' ? '' : ` - ${filters[filter]}`} `;
|
||||
|
||||
return await utils.ProcessItems(ctx, currentUrl, title);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/makers/7R',
|
||||
parameters: { id: '编号,可在片商页 URL 中找到', filter: '过滤,见下表,默认为 `全部`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/rankings',
|
||||
parameters: { category: '分类,见下表,默认为 `有碼`', time: '时间,见下表,默认为 `日榜`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/search/巨乳',
|
||||
parameters: { keyword: '关键字,默认为空', filter: '过滤,见下表,默认为 `可播放`', sort: '排序,见下表,默认为 `按相关度排序`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/series/1NW',
|
||||
parameters: { id: '编号,可在系列页 URL 中找到', filter: '过滤,见下表,默认为 `全部`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,13 @@ export const route: Route = {
|
|||
example: '/javdb/tags/c2=5&c10=1',
|
||||
parameters: { query: '筛选,默认为 `c10=1`', category: '分类,见下表,默认为 `有碼`' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requireConfig: [
|
||||
{
|
||||
name: 'JAVDB_SESSION',
|
||||
description: 'JavDB登陆后的session值,可在控制台的cookie下查找 `_jdb_session` 的值,即可获取',
|
||||
optional: true,
|
||||
},
|
||||
],
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: true,
|
||||
supportBT: false,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import got from '@/utils/got';
|
|||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { config } from '@/config';
|
||||
import { Cookie, CookieJar } from 'tough-cookie';
|
||||
|
||||
import ConfigNotFoundError from '@/errors/types/config-not-found';
|
||||
const allowDomain = new Set(['javdb.com', 'javdb36.com', 'javdb007.com', 'javdb521.com']);
|
||||
|
||||
|
|
@ -15,9 +17,22 @@ const ProcessItems = async (ctx, currentUrl, title) => {
|
|||
|
||||
const rootUrl = `https://${domain}`;
|
||||
|
||||
const cookieJar = new CookieJar();
|
||||
|
||||
if (config.javdb.session) {
|
||||
const cookie = Cookie.fromJSON({
|
||||
key: '_jdb_session',
|
||||
value: config.javdb.session,
|
||||
domain,
|
||||
path: '/',
|
||||
});
|
||||
cookie && cookieJar.setCookie(cookie, rootUrl);
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url.href,
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
const $ = load(response.data);
|
||||
|
|
@ -42,6 +57,7 @@ const ProcessItems = async (ctx, currentUrl, title) => {
|
|||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
const content = load(detailResponse.data);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|||
import { http, HttpResponse } from 'msw';
|
||||
import got from '@/utils/got';
|
||||
import { config } from '@/config';
|
||||
import { Cookie, CookieJar } from 'tough-cookie';
|
||||
|
||||
describe('got', () => {
|
||||
it('headers', async () => {
|
||||
|
|
@ -56,4 +57,20 @@ describe('got', () => {
|
|||
expect(response.body instanceof Buffer).toBe(true);
|
||||
expect(response.data instanceof Buffer).toBe(true);
|
||||
});
|
||||
|
||||
it('cookieJar', async () => {
|
||||
const cookieJar = new CookieJar();
|
||||
const cookie = Cookie.fromJSON({
|
||||
key: 'cookie',
|
||||
value: 'test',
|
||||
domain: 'rsshub.test',
|
||||
path: '/',
|
||||
});
|
||||
cookie && cookieJar.setCookie(cookie, 'http://rsshub.test');
|
||||
const { data } = await got.get('http://rsshub.test/headers', {
|
||||
cookieJar,
|
||||
});
|
||||
|
||||
expect(data.cookie).toBe('cookie=test; Domain=rsshub.test; Path=/');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -53,6 +53,17 @@ const getFakeGot = (defaultOptions?: any) => {
|
|||
delete options.parseResponse;
|
||||
}
|
||||
|
||||
if (options.cookieJar) {
|
||||
const cookies = options.cookieJar.getCookiesSync(request);
|
||||
if (cookies.length) {
|
||||
if (!options.headers) {
|
||||
options.headers = {};
|
||||
}
|
||||
options.headers.cookie = cookies.join('; ');
|
||||
}
|
||||
delete options.cookieJar;
|
||||
}
|
||||
|
||||
const response = ofetch(request, options);
|
||||
|
||||
if (options?.responseType === 'arrayBuffer') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue