From aa46e600e1394cdcc23123b8786cf9edc2f336cc Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 26 Jun 2026 19:48:11 +0800 Subject: [PATCH] feat(route): add pawchive (#22340) --- lib/routes/pawchive/const.ts | 4 + lib/routes/pawchive/index.tsx | 137 +++++++++++++++++++++++++++++++ lib/routes/pawchive/namespace.ts | 7 ++ lib/routes/pawchive/types.ts | 18 ++++ 4 files changed, 166 insertions(+) create mode 100644 lib/routes/pawchive/const.ts create mode 100644 lib/routes/pawchive/index.tsx create mode 100644 lib/routes/pawchive/namespace.ts create mode 100644 lib/routes/pawchive/types.ts diff --git a/lib/routes/pawchive/const.ts b/lib/routes/pawchive/const.ts new file mode 100644 index 000000000..b56caaf74 --- /dev/null +++ b/lib/routes/pawchive/const.ts @@ -0,0 +1,4 @@ +export const baseUrl = 'https://pawchive.st'; +export const apiBaseUrl = `${baseUrl}/api/v1`; +export const thumbnailUrl = 'https://img.pawchive.st/thumbnail/data'; +export const fileUrl = 'https://file.pawchive.st/data'; diff --git a/lib/routes/pawchive/index.tsx b/lib/routes/pawchive/index.tsx new file mode 100644 index 000000000..9403b5719 --- /dev/null +++ b/lib/routes/pawchive/index.tsx @@ -0,0 +1,137 @@ +import type { Context } from 'hono'; +import { raw } from 'hono/html'; +import { renderToString } from 'hono/jsx/dom/server'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +import { apiBaseUrl, baseUrl, fileUrl, thumbnailUrl } from './const'; +import type { PawchiveFile, PawchivePost } from './types'; + +export const route: Route = { + path: '/:service/:id', + categories: ['anime'], + example: '/pawchive/fanbox/22445', + parameters: { + service: 'service, either `patreon` or `fanbox`', + id: 'User id, can be found in URL', + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + nsfw: true, + }, + radar: [ + { + source: ['pawchive.st/'], + target: '', + }, + { + source: ['pawchive.st/:service/user/:id'], + target: '/:service/:id', + }, + ], + name: 'Posts', + maintainers: ['TonyRL'], + handler, +}; + +const processPostFiles = (post: PawchivePost) => + [post.file, ...post.attachments] + .map((file) => { + if (!file.path) { + return null; + } + + return { + name: file.name, + path: file.path, + }; + }) + .filter(Boolean) as PawchiveFile[]; + +const render = (post: PawchivePost, files: PawchiveFile[]) => + renderToString( + <> + {files.length > 0 &&

Downloads / Files

} + {files.length > 0 && ( + + )} + {post.content &&

Content

} + {post.content && raw(post.content)} + + ); + +async function handler(ctx: Context) { + const { service, id } = ctx.req.param(); + + const apiUrl = `${apiBaseUrl}/${service}/user/${id}`; + const response = await ofetch(apiUrl); + + if (response.length === 0) { + throw new Error('The user does not exist.'); + } + + const author = (await cache.tryGet(`pawchive:${service}:${id}`, async () => { + const profileUrl = `${apiBaseUrl}/${service}/user/${id}/profile`; + const data = await ofetch(profileUrl); + return data.name || 'Unknown User'; + })) as Promise; + + const items = response.map((post) => ({ + title: post.title || 'Untitled Post', + description: render(post, processPostFiles(post)), + author, + pubDate: parseDate(post.published), + link: `${baseUrl}/${post.service}/user/${post.user}/post/${post.id}`, + guid: `pawchive:${post.service}:${post.user}:post:${post.id}`, + })); + + return { + title: `Posts of ${author} from ${service} | Pawchive`, + link: `${baseUrl}/${service}/user/${id}`, + image: `${baseUrl}/icons/${service}/${id}`, + item: items, + }; +} diff --git a/lib/routes/pawchive/namespace.ts b/lib/routes/pawchive/namespace.ts new file mode 100644 index 000000000..127e5537d --- /dev/null +++ b/lib/routes/pawchive/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Pawchive', + url: 'pawchive.st', + lang: 'en', +}; diff --git a/lib/routes/pawchive/types.ts b/lib/routes/pawchive/types.ts new file mode 100644 index 000000000..af67f60b1 --- /dev/null +++ b/lib/routes/pawchive/types.ts @@ -0,0 +1,18 @@ +export interface PawchivePost { + id: string; + user: string; + service: string; + title: string; + content: string; + shared_file: boolean; + added: string; + published: string; + edited: string; + file: PawchiveFile | Record; + attachments: PawchiveFile[]; +} + +export interface PawchiveFile { + name: string; + path: string; +}