feat(konachan): add SFW option for konachan via /sfw prefix (#19273)

* update post.ts

* update parameter description

* update

* update

* update
This commit is contained in:
sineeeee
2025-06-04 16:12:22 +08:00
committed by GitHub
parent d6c1b77142
commit 4e958708f1
+26 -18
View File
@@ -3,7 +3,10 @@ import got from '@/utils/got';
import queryString from 'query-string';
export const route: Route = {
path: '/post/popular_recent/:period?',
path: [
'/post/popular_recent/:period?', // 对应 konachan.com
'/sfw/post/popular_recent/:period?', // 对应 konachan.net(SFW)
],
categories: ['picture'],
view: ViewType.Pictures,
example: '/konachan/post/popular_recent/1d',
@@ -18,14 +21,18 @@ export const route: Route = {
],
default: '1d',
},
safe_search: {
description: '是否使用无r18的站点konachan.net,若是,则在路径前加上 `/sfw`,如`/konachan/sfw/post/popular_recent/1d`,若否则默认使用 konachan.com',
default: 'false',
},
},
radar: [
{
source: ['konachan.com/post'],
source: ['konachan.com/post', 'konachan.net/post'],
},
],
name: 'Popular Recent Posts',
maintainers: ['magic-akari', 'NekoAria'],
maintainers: ['magic-akari', 'NekoAria', 'sineeeee'],
description: `| 最近 24 小时 | 最近一周 | 最近一月 | 最近一年 |
| ------- | -------- | ------- | -------- |
| 1d | 1w | 1m | 1y |`,
@@ -34,9 +41,11 @@ export const route: Route = {
async function handler(ctx) {
const { period = '1d' } = ctx.req.param();
const isSfw = ctx.req.path.includes('/sfw');
const baseUrl = isSfw ? 'https://konachan.net' : 'https://konachan.com';
const response = await got({
url: 'https://konachan.com/post/popular_recent.json',
url: `${baseUrl}/post/popular_recent.json`,
searchParams: queryString.stringify({
period,
}),
@@ -51,7 +60,7 @@ async function handler(ctx) {
'1y': 'Last year',
};
const mime = {
const mime: Record<string, string> = {
jpg: 'jpeg',
png: 'png',
};
@@ -59,24 +68,23 @@ async function handler(ctx) {
const title = titles[period];
return {
title: `${title} - konachan.com`,
link: `https://konachan.com/post/popular_recent?period=${period}`,
title: `${title} - ${isSfw ? 'konachan.net' : 'konachan.com'}`,
link: `${baseUrl}/post/popular_recent?period=${period}`,
item: posts.map((post) => ({
title: post.tags,
id: `${ctx.path}#${post.id}`,
guid: `${ctx.path}#${post.id}`,
link: `https://konachan.com/post/show/${post.id}`,
id: `${ctx.req.path}#${post.id}`,
guid: `${ctx.req.path}#${post.id}`,
link: `${baseUrl}/post/show/${post.id}`,
author: post.author,
pubDate: new Date(post.created_at * 1e3).toUTCString(),
description: (() => {
const result = [`<img src="${post.sample_url}" />`];
result.push(`<p>Rating:${post.rating}</p> <p>Score:${post.score}</p>`);
if (post.source) {
result.push(`<a href="${post.source}">Source</a>`);
}
if (post.parent_id) {
result.push(`<a href="https://konachan.com/post/show/${post.parent_id}">Parent</a>`);
}
const result: string[] = [];
result.push(
`<img src="${post.sample_url}" />`,
`<p>Rating: ${post.rating}</p><p>Score: ${post.score}</p>`,
...(post.source ? [`<a href="${post.source}">Source</a>`] : []),
...(post.parent_id ? [`<a href="${baseUrl}/post/show/${post.parent_id}">Parent</a>`] : [])
);
return result.join('');
})(),
media: {