Skip to content

Commit cfb3982

Browse files
committed
fix(api): update getResources method to fetch from admin config and add safety checks for SourceConfig
1 parent 7f00853 commit cfb3982

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "OrionTV",
33
"private": true,
44
"main": "expo-router/entry",
5-
"version": "1.3.3",
5+
"version": "1.3.4",
66
"scripts": {
77
"start": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
88
"android": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo run:android",

services/api.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,31 @@ export class API {
208208
}
209209

210210
async getResources(signal?: AbortSignal): Promise<ApiSite[]> {
211-
const url = `/api/search/resources`;
211+
const url = `/api/admin/config`;
212212
const response = await this._fetch(url, { signal });
213-
return response.json();
213+
const config = await response.json();
214+
215+
// 添加安全检查
216+
if (!config || !config.Config.SourceConfig) {
217+
console.warn('API response missing SourceConfig:', config);
218+
return [];
219+
}
220+
221+
// 确保 SourceConfig 是数组
222+
if (!Array.isArray(config.Config.SourceConfig)) {
223+
console.warn('SourceConfig is not an array:', config.Config.SourceConfig);
224+
return [];
225+
}
226+
227+
// 过滤并验证每个站点配置
228+
return config.Config.SourceConfig
229+
.filter((site: any) => site && !site.disabled)
230+
.map((site: any) => ({
231+
key: site.key || '',
232+
api: site.api || '',
233+
name: site.name || '',
234+
detail: site.detail
235+
}));
214236
}
215237

216238
async getVideoDetail(source: string, id: string): Promise<VideoDetail> {

0 commit comments

Comments
 (0)