fix(route/pawchive): add enclosure support and fix media URLs (#22739)

* fix(route): pawchive - add enclosure support and fix media URLs

* Address github-advanced-security problems

* Change namespace to pawchive.pw

* Fix pawchive domain in radar
This commit is contained in:
Ananya 2026-07-21 21:00:44 +02:00 committed by GitHub
parent 737cf6063b
commit 0eb05b56a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 15 deletions

View File

@ -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;

View File

@ -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<string>;
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`,

View File

@ -2,6 +2,6 @@ import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Pawchive',
url: 'pawchive.st',
url: 'pawchive.pw',
lang: 'en',
};