RSSHub/lib/v2/ehentai/search.js

37 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const EhAPI = require('./ehapi');
module.exports = async (ctx) => {
const page = ctx.params.page;
let params = ctx.params.params;
const routeParams = new URLSearchParams(ctx.params.routeParams);
const bittorrent = routeParams.get('bittorrent') || false;
const embed_thumb = routeParams.get('embed_thumb') || false;
let items;
if (page) {
// 如果定义了page就要覆盖params
params = params.replace(/&*next=[^&]$/, '').replace(/next=[^&]&/, '');
items = await EhAPI.getSearchItems(ctx.cache, params, page, bittorrent, embed_thumb);
} else {
items = await EhAPI.getSearchItems(ctx.cache, params, undefined, bittorrent, embed_thumb);
}
let title = params;
const match = /f_search=([^&]+)/.exec(title);
if (match !== null) {
title = match[1];
}
if (EhAPI.from_ex) {
ctx.state.data = {
title: title + ' - ExHentai Search ',
link: `https://exhentai.org/?${params}`,
item: items,
};
} else {
ctx.state.data = {
title: title + ' - E-Hentai Search ',
link: `https://e-hentai.org/?${params}`,
item: items,
};
}
};