mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-28 06:54:42 +08:00
refactor(api): simplify getResources method and update API endpoint /api/search/resources
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
|
||||
import Logger from '@/utils/Logger';
|
||||
|
||||
const logger = Logger.withTag('API');
|
||||
|
||||
// region: --- Interface Definitions ---
|
||||
export interface DoubanItem {
|
||||
title: string;
|
||||
@@ -213,43 +208,9 @@ export class API {
|
||||
}
|
||||
|
||||
async getResources(signal?: AbortSignal): Promise<ApiSite[]> {
|
||||
const url = `/api/admin/config`;
|
||||
const url = `/api/search/resources`;
|
||||
const response = await this._fetch(url, { signal });
|
||||
const config = await response.json();
|
||||
|
||||
// 添加安全检查
|
||||
if (!config || !config.Config.SourceConfig) {
|
||||
logger.warn('API response missing SourceConfig:', config);
|
||||
return [];
|
||||
}
|
||||
|
||||
// 确保 SourceConfig 是数组
|
||||
if (!Array.isArray(config.Config.SourceConfig)) {
|
||||
logger.warn('SourceConfig is not an array:', config.Config.SourceConfig);
|
||||
return [];
|
||||
}
|
||||
|
||||
// 过滤并验证每个站点配置,同时进行去重
|
||||
const seenKeys = new Set<string>();
|
||||
const uniqueSites: ApiSite[] = [];
|
||||
|
||||
config.Config.SourceConfig
|
||||
.filter((site: any) => site && !site.disabled)
|
||||
.forEach((site: any) => {
|
||||
const key = site.key || '';
|
||||
// 基于 key 字段去重
|
||||
if (key && !seenKeys.has(key)) {
|
||||
seenKeys.add(key);
|
||||
uniqueSites.push({
|
||||
key: key,
|
||||
api: site.api || '',
|
||||
name: site.name || '',
|
||||
detail: site.detail
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return uniqueSites;
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async getVideoDetail(source: string, id: string): Promise<VideoDetail> {
|
||||
|
||||
Reference in New Issue
Block a user