diff --git a/lib/routes/pawchive/const.ts b/lib/routes/pawchive/const.ts index b56caaf74..f060dd1b6 100644 --- a/lib/routes/pawchive/const.ts +++ b/lib/routes/pawchive/const.ts @@ -1,4 +1,10 @@ -export const baseUrl = 'https://pawchive.st'; +export const baseUrl = 'https://pawchive.pw'; export const apiBaseUrl = `${baseUrl}/api/v1`; -export const thumbnailUrl = 'https://img.pawchive.st/thumbnail/data'; -export const fileUrl = 'https://file.pawchive.st/data'; +export const thumbnailUrl = 'https://img.pawchive.pw/thumbnail/data'; +export const fileUrl = 'https://file.pawchive.pw/data'; + +export const MIME_TYPE_MAP = { + m4a: 'audio/mp4', + mp3: 'audio/mpeg', + mp4: 'video/mp4', +} as const; diff --git a/lib/routes/pawchive/index.tsx b/lib/routes/pawchive/index.tsx index 9403b5719..5228b75e1 100644 --- a/lib/routes/pawchive/index.tsx +++ b/lib/routes/pawchive/index.tsx @@ -1,3 +1,4 @@ +import { load } from 'cheerio'; import type { Context } from 'hono'; import { raw } from 'hono/html'; import { renderToString } from 'hono/jsx/dom/server'; @@ -7,9 +8,34 @@ import cache from '@/utils/cache'; import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; -import { apiBaseUrl, baseUrl, fileUrl, thumbnailUrl } from './const'; +import { apiBaseUrl, baseUrl, fileUrl, MIME_TYPE_MAP, thumbnailUrl } from './const'; import type { PawchiveFile, PawchivePost } from './types'; +function generateEnclosureInfo(htmlContent: string): { enclosure_url?: string; enclosure_type?: string } { + const $ = load(htmlContent); + let enclosureInfo = {}; + + $('audio source, video source').each((_, el) => { + const src = $(el).attr('src'); + if (!src) { + return; + } + + const extension = src.replace(/.*\./, '').toLowerCase(); + const mimeType = MIME_TYPE_MAP[extension as keyof typeof MIME_TYPE_MAP]; + + if (mimeType) { + enclosureInfo = { + enclosure_url: src, + enclosure_type: mimeType, + }; + return false; + } + }); + + return enclosureInfo; +} + export const route: Route = { path: '/:service/:id', categories: ['anime'], @@ -29,11 +55,11 @@ export const route: Route = { }, radar: [ { - source: ['pawchive.st/'], + source: ['pawchive.pw/'], target: '', }, { - source: ['pawchive.st/:service/user/:id'], + source: ['pawchive.pw/:service/user/:id'], target: '/:service/:id', }, ], @@ -119,14 +145,18 @@ async function handler(ctx: Context) { 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}`, - })); + const items = response.map((post) => { + const description = render(post, processPostFiles(post)); + return { + title: post.title || 'Untitled Post', + description, + author, + pubDate: parseDate(post.published), + link: `${baseUrl}/${post.service}/user/${post.user}/post/${post.id}`, + guid: `pawchive:${post.service}:${post.user}:post:${post.id}`, + ...generateEnclosureInfo(description), + }; + }); return { title: `Posts of ${author} from ${service} | Pawchive`, diff --git a/lib/routes/pawchive/namespace.ts b/lib/routes/pawchive/namespace.ts index 127e5537d..3ee8cf763 100644 --- a/lib/routes/pawchive/namespace.ts +++ b/lib/routes/pawchive/namespace.ts @@ -2,6 +2,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'Pawchive', - url: 'pawchive.st', + url: 'pawchive.pw', lang: 'en', };