mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 03:36:29 +08:00
fix(api): update getResources method to fetch from admin config and add safety checks for SourceConfig
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"name": "OrionTV",
|
"name": "OrionTV",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "expo-router/entry",
|
"main": "expo-router/entry",
|
||||||
"version": "1.3.3",
|
"version": "1.3.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
"start": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
||||||
"android": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo run:android",
|
"android": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo run:android",
|
||||||
|
|||||||
@@ -208,9 +208,31 @@ export class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getResources(signal?: AbortSignal): Promise<ApiSite[]> {
|
async getResources(signal?: AbortSignal): Promise<ApiSite[]> {
|
||||||
const url = `/api/search/resources`;
|
const url = `/api/admin/config`;
|
||||||
const response = await this._fetch(url, { signal });
|
const response = await this._fetch(url, { signal });
|
||||||
return response.json();
|
const config = await response.json();
|
||||||
|
|
||||||
|
// 添加安全检查
|
||||||
|
if (!config || !config.Config.SourceConfig) {
|
||||||
|
console.warn('API response missing SourceConfig:', config);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保 SourceConfig 是数组
|
||||||
|
if (!Array.isArray(config.Config.SourceConfig)) {
|
||||||
|
console.warn('SourceConfig is not an array:', config.Config.SourceConfig);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过滤并验证每个站点配置
|
||||||
|
return config.Config.SourceConfig
|
||||||
|
.filter((site: any) => site && !site.disabled)
|
||||||
|
.map((site: any) => ({
|
||||||
|
key: site.key || '',
|
||||||
|
api: site.api || '',
|
||||||
|
name: site.name || '',
|
||||||
|
detail: site.detail
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVideoDetail(source: string, id: string): Promise<VideoDetail> {
|
async getVideoDetail(source: string, id: string): Promise<VideoDetail> {
|
||||||
|
|||||||
Reference in New Issue
Block a user