修复测活列表状态
This commit is contained in:
@@ -9,6 +9,16 @@ import { hasFeaturePermission } from '@/lib/permissions';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
const pickText = (value: any): string => {
|
||||
if (value === undefined || value === null) return '';
|
||||
const first = Array.isArray(value) ? value[0] : value;
|
||||
if (first === undefined || first === null) return '';
|
||||
if (typeof first === 'object') {
|
||||
return String(first._ ?? first.$?.url ?? first.$?.href ?? '').trim();
|
||||
}
|
||||
return String(first).trim();
|
||||
};
|
||||
|
||||
/**
|
||||
* POST /api/acg/acgrip
|
||||
* 搜索 ACG.RIP 磁力资源(仅管理员和站长可用,支持分页)
|
||||
@@ -86,27 +96,35 @@ export async function POST(req: NextRequest) {
|
||||
const items = parsed.rss.channel[0].item;
|
||||
|
||||
// 转换为标准格式
|
||||
const results = items.map((item: any) => {
|
||||
const description = item.description?.[0] || '';
|
||||
const results = items.map((item: any, index: number) => {
|
||||
const title = pickText(item.title);
|
||||
const link = pickText(item.link);
|
||||
const pubDate = pickText(item.pubDate);
|
||||
const description = pickText(item.description);
|
||||
const torrentUrl =
|
||||
pickText(item.enclosure?.[0]?.$?.url) ||
|
||||
pickText(item.enclosure?.[0]?.$?.href) ||
|
||||
pickText(item.enclosure?.[0]);
|
||||
const guid =
|
||||
pickText(item.guid) ||
|
||||
torrentUrl ||
|
||||
link ||
|
||||
`${title}-${pubDate}-${index}`;
|
||||
|
||||
// 提取描述中的图片(如果有)
|
||||
let images: string[] = [];
|
||||
if (description) {
|
||||
const imgMatches = description.match(/src="([^"]+)"/g);
|
||||
if (imgMatches) {
|
||||
images = imgMatches.map((match: string) => {
|
||||
const urlMatch = match.match(/src="([^"]+)"/);
|
||||
return urlMatch ? urlMatch[1] : '';
|
||||
}).filter(Boolean);
|
||||
images = imgMatches
|
||||
.map((match: string) => {
|
||||
const urlMatch = match.match(/src="([^"]+)"/);
|
||||
return urlMatch ? urlMatch[1] : '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
}
|
||||
|
||||
const title = item.title?.[0] || '';
|
||||
const link = item.link?.[0] || '';
|
||||
const guid = item.guid?.[0] || link || `${title}-${item.pubDate?.[0] || ''}`;
|
||||
const pubDate = item.pubDate?.[0] || '';
|
||||
const torrentUrl = item.enclosure?.[0]?.$?.url || '';
|
||||
|
||||
return {
|
||||
title,
|
||||
link,
|
||||
|
||||
@@ -9,6 +9,16 @@ import { hasFeaturePermission } from '@/lib/permissions';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
const pickText = (value: any): string => {
|
||||
if (value === undefined || value === null) return '';
|
||||
const first = Array.isArray(value) ? value[0] : value;
|
||||
if (first === undefined || first === null) return '';
|
||||
if (typeof first === 'object') {
|
||||
return String(first._ ?? first.$?.url ?? first.$?.href ?? '').trim();
|
||||
}
|
||||
return String(first).trim();
|
||||
};
|
||||
|
||||
/**
|
||||
* POST /api/acg/dmhy
|
||||
* 搜索 动漫花园 (share.dmhy.org) RSS(仅管理员和站长可用)
|
||||
@@ -92,13 +102,21 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
const items = parsed.rss.channel[0].item;
|
||||
|
||||
const results = items.map((item: any) => {
|
||||
const title = item.title?.[0] || '';
|
||||
const link = item.link?.[0] || '';
|
||||
const guid = item.guid?.[0] || link || `${title}-${item.pubDate?.[0] || ''}`;
|
||||
const pubDate = item.pubDate?.[0] || '';
|
||||
const description = item.description?.[0] || '';
|
||||
const torrentUrl = item.enclosure?.[0]?.$?.url || '';
|
||||
const results = items.map((item: any, index: number) => {
|
||||
const title = pickText(item.title);
|
||||
const link = pickText(item.link);
|
||||
const pubDate = pickText(item.pubDate);
|
||||
const description = pickText(item.description);
|
||||
const torrentUrl =
|
||||
pickText(item.enclosure?.[0]?.$?.url) ||
|
||||
pickText(item.enclosure?.[0]?.$?.href) ||
|
||||
pickText(item.enclosure?.[0]);
|
||||
// guid 在 xml2js 下常为 { _: url, $: { isPermaLink } },必须抽成纯字符串,否则前端 key 全变成 [object Object]
|
||||
const guid =
|
||||
pickText(item.guid) ||
|
||||
torrentUrl ||
|
||||
link ||
|
||||
`${title}-${pubDate}-${index}`;
|
||||
|
||||
// 提取描述中的图片(如果有)
|
||||
let images: string[] = [];
|
||||
|
||||
@@ -11,8 +11,12 @@ export const runtime = 'nodejs';
|
||||
|
||||
const pickText = (value: any): string => {
|
||||
if (value === undefined || value === null) return '';
|
||||
if (Array.isArray(value)) return String(value[0] ?? '');
|
||||
return String(value);
|
||||
const first = Array.isArray(value) ? value[0] : value;
|
||||
if (first === undefined || first === null) return '';
|
||||
if (typeof first === 'object') {
|
||||
return String(first._ ?? first.$?.url ?? first.$?.href ?? '').trim();
|
||||
}
|
||||
return String(first).trim();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -97,24 +101,28 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
const items = parsed.rss.channel[0].item;
|
||||
|
||||
const results = items.map((item: any) => {
|
||||
const results = items.map((item: any, index: number) => {
|
||||
const title = pickText(item.title);
|
||||
const link = pickText(item.link);
|
||||
const guid = pickText(item.guid) || link || `${title}-${pickText(item.torrent?.[0]?.pubDate)}`;
|
||||
const pubDate =
|
||||
pickText(item.pubDate) ||
|
||||
pickText(item.torrent?.[0]?.pubDate) ||
|
||||
pickText(item['dc:date']);
|
||||
|
||||
const description =
|
||||
pickText(item.description) ||
|
||||
pickText(item['content:encoded']) ||
|
||||
'';
|
||||
|
||||
const torrentUrl =
|
||||
pickText(item.enclosure?.[0]?.$?.url) ||
|
||||
pickText(item.enclosure?.[0]?.$?.href) ||
|
||||
pickText(item.enclosure?.[0]) ||
|
||||
'';
|
||||
// guid 必须是唯一纯字符串,避免 xml 对象导致前端 key 冲突
|
||||
const guid =
|
||||
pickText(item.guid) ||
|
||||
torrentUrl ||
|
||||
link ||
|
||||
`${title}-${pubDate}-${index}`;
|
||||
|
||||
// 提取描述中的图片(如果有)
|
||||
let images: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user