feat(route): recover route konachan (#16934)

* feat(route): recover route konachan

* fix(yande): correct maintainers list format

* fix: namespace name

---------
This commit is contained in:
Neko Aria 2024-09-27 01:24:01 +08:00 committed by GitHub
parent 1d22c0ad38
commit 6e99633cf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 93 additions and 77 deletions

View File

@ -47,14 +47,6 @@ router.get('/huya/live/:id', lazyloadRouteHandler('./routes/huya/live'));
// f-droid
// router.get('/fdroid/apprelease/:app', lazyloadRouteHandler('./routes/fdroid/apprelease'));
// konachan
router.get('/konachan/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.com/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.net/post/popular_recent', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.com/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
router.get('/konachan.net/post/popular_recent/:period', lazyloadRouteHandler('./routes/konachan/post-popular-recent'));
// PornHub
// router.get('/pornhub/category/:caty', lazyloadRouteHandler('./routes/pornhub/category'));
// router.get('/pornhub/search/:keyword', lazyloadRouteHandler('./routes/pornhub/search'));

View File

@ -1,67 +0,0 @@
const got = require('@/utils/got');
const queryString = require('query-string');
module.exports = async (ctx) => {
const { period = '1d' } = ctx.params;
const baseUrl = ctx.path.startsWith('/konachan.net') ? 'https://konachan.net' : 'https://konachan.com';
const safemode = ctx.path.startsWith('/konachan.net');
const response = await got({
method: 'get',
url: `${baseUrl}/post/popular_recent.json`,
searchParams: queryString.stringify({
period,
}),
});
const posts = response.data;
const titles = {
'1d': 'Exploring last 24 hours ',
'1w': 'Exploring last week',
'1m': 'Exploring last month',
'1y': 'Exploring last year',
};
const title = titles[period] || titles['1d'];
ctx.state.data = {
title: `${title} - Konachan Anime Wallpapers`,
link: `${baseUrl}/post/popular_recent`,
item: posts
.filter((post) => !(safemode && post.rating !== 's'))
.map((post) => {
const content = (url) => {
if (url.startsWith('//')) {
url = 'https:' + url;
}
let result = `<img src="${url}" />`;
if (post.source) {
result += `<a href="${post.source}">source</a>`;
}
if (post.parent_id) {
result += `<a href="${baseUrl}/post/show/${post.parent_id}">parent</a>`;
}
return result;
};
const created_at = post.created_at * 1e3;
return {
title: post.tags,
id: `${ctx.path}#${post.id}`,
guid: `${ctx.path}#${post.id}`,
link: `${baseUrl}/post/show/${post.id}`,
author: post.author,
published: new Date(created_at).toISOString(),
pubDate: new Date(created_at).toUTCString(),
description: content(post.sample_url),
summary: content(post.sample_url),
content: { html: content(post.file_url) },
image: post.file_url,
category: post.tags.split(/\s+/),
};
}),
};
};

View File

@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Konachan.com Anime Wallpapers',
url: 'konachan.com',
description: `konachan post`,
};

View File

@ -0,0 +1,84 @@
import { Route } from '@/types';
import got from '@/utils/got';
import queryString from 'query-string';
export const route: Route = {
path: '/post/popular_recent/:period?',
categories: ['picture'],
example: '/konachan/post/popular_recent/1d',
parameters: {
period: '展示时间',
},
radar: [
{
source: ['konachan.com/post'],
},
],
name: 'Popular Recent Posts',
maintainers: ['magic-akari', 'NekoAria'],
description: `| 最近 24 小时 | 最近一周 | 最近一月 | 最近一年 |
| ------- | -------- | ------- | -------- |
| 1d | 1w | 1m | 1y |`,
handler,
};
async function handler(ctx) {
const { period = '1d' } = ctx.req.param();
const response = await got({
url: 'https://konachan.com/post/popular_recent.json',
searchParams: queryString.stringify({
period,
}),
});
const posts = response.data;
const titles = {
'1d': 'Last 24 hours',
'1w': 'Last week',
'1m': 'Last month',
'1y': 'Last year',
};
const mime = {
jpg: 'jpeg',
png: 'png',
};
const title = titles[period];
return {
title: `${title} - konachan.com`,
link: `https://konachan.com/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}`,
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>`);
}
return result.join('');
})(),
media: {
content: {
url: post.file_url,
type: `image/${mime[post.file_ext]}`,
},
thumbnail: {
url: post.preview_url,
},
},
category: post.tags.split(/\s+/),
})),
};
}

View File

@ -15,10 +15,10 @@ export const route: Route = {
},
],
name: 'posts',
maintainers: ['fashioncj'],
maintainers: ['fashioncj', 'NekoAria'],
description: `| 最近 24 小时 | 最近一周 | 最近一月 | 最近一年 |
| ------- | -------- | ------- | -------- |
| 1d | 1w | 1m 1y`,
| 1d | 1w | 1m | 1y |`,
handler,
};