From 6e99633cf2a2e4c8229a30e52e9ed156a9da64b1 Mon Sep 17 00:00:00 2001
From: Neko Aria <990879119@qq.com>
Date: Fri, 27 Sep 2024 01:24:01 +0800
Subject: [PATCH] feat(route): recover route konachan (#16934)
* feat(route): recover route konachan
* fix(yande): correct maintainers list format
* fix: namespace name
---------
---
lib/router.js | 8 --
.../konachan/post-popular-recent.js | 67 ---------------
lib/routes/konachan/namespace.ts | 7 ++
lib/routes/konachan/post.ts | 84 +++++++++++++++++++
lib/routes/yande/post.ts | 4 +-
5 files changed, 93 insertions(+), 77 deletions(-)
delete mode 100644 lib/routes-deprecated/konachan/post-popular-recent.js
create mode 100644 lib/routes/konachan/namespace.ts
create mode 100644 lib/routes/konachan/post.ts
diff --git a/lib/router.js b/lib/router.js
index 4033bb6ba..063ef5ab3 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -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'));
diff --git a/lib/routes-deprecated/konachan/post-popular-recent.js b/lib/routes-deprecated/konachan/post-popular-recent.js
deleted file mode 100644
index e500e3ab7..000000000
--- a/lib/routes-deprecated/konachan/post-popular-recent.js
+++ /dev/null
@@ -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 = ``;
- if (post.source) {
- result += `source`;
- }
- if (post.parent_id) {
- result += `parent`;
- }
- 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+/),
- };
- }),
- };
-};
diff --git a/lib/routes/konachan/namespace.ts b/lib/routes/konachan/namespace.ts
new file mode 100644
index 000000000..8c3dd7076
--- /dev/null
+++ b/lib/routes/konachan/namespace.ts
@@ -0,0 +1,7 @@
+import type { Namespace } from '@/types';
+
+export const namespace: Namespace = {
+ name: 'Konachan.com Anime Wallpapers',
+ url: 'konachan.com',
+ description: `konachan post`,
+};
diff --git a/lib/routes/konachan/post.ts b/lib/routes/konachan/post.ts
new file mode 100644
index 000000000..6540c02e2
--- /dev/null
+++ b/lib/routes/konachan/post.ts
@@ -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 = [`
`];
+ result.push(`
Rating:${post.rating}
Score:${post.score}
`); + if (post.source) { + result.push(`Source`); + } + if (post.parent_id) { + result.push(`Parent`); + } + 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+/), + })), + }; +} diff --git a/lib/routes/yande/post.ts b/lib/routes/yande/post.ts index fc1ba6db9..287fde585 100644 --- a/lib/routes/yande/post.ts +++ b/lib/routes/yande/post.ts @@ -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, };