修复emby分类返回空数组
This commit is contained in:
@@ -9,16 +9,8 @@ export const dynamic = 'force-dynamic'; // 禁用缓存
|
||||
* 获取所有启用的Emby源列表
|
||||
*/
|
||||
export async function GET() {
|
||||
console.log('=================================');
|
||||
console.log('[Emby Sources API] !!!!! 路由被调用了 !!!!!');
|
||||
console.log('[Emby Sources API] 时间戳:', new Date().toISOString());
|
||||
console.log('=================================');
|
||||
|
||||
try {
|
||||
console.log('[Emby Sources API] 开始获取Emby源列表');
|
||||
const sources = await embyManager.getEnabledSources();
|
||||
console.log('[Emby Sources API] 获取到的源数量:', sources.length);
|
||||
console.log('[Emby Sources API] 源详情:', JSON.stringify(sources, null, 2));
|
||||
|
||||
return NextResponse.json({
|
||||
sources: sources.map(s => ({
|
||||
|
||||
@@ -302,18 +302,11 @@ async function getInitConfig(configFile: string, subConfig: {
|
||||
export async function getConfig(): Promise<AdminConfig> {
|
||||
// 直接使用内存缓存
|
||||
if (cachedConfig) {
|
||||
console.log('[Config] 使用缓存的配置');
|
||||
console.log('[Config] 缓存中EmbyConfig存在:', !!cachedConfig.EmbyConfig);
|
||||
console.log('[Config] 缓存中EmbyConfig.Sources存在:', !!cachedConfig.EmbyConfig?.Sources);
|
||||
if (cachedConfig.EmbyConfig?.Sources) {
|
||||
console.log('[Config] 缓存中Sources长度:', cachedConfig.EmbyConfig.Sources.length);
|
||||
}
|
||||
return cachedConfig;
|
||||
}
|
||||
|
||||
// 如果正在初始化,等待初始化完成
|
||||
if (configInitPromise) {
|
||||
console.log('[Config] 等待配置初始化完成');
|
||||
return configInitPromise;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,24 +43,14 @@ class EmbyManager {
|
||||
*/
|
||||
private async getSources(): Promise<EmbySourceConfig[]> {
|
||||
const config = await getConfig();
|
||||
console.log('[EmbyManager] 获取配置完成');
|
||||
console.log('[EmbyManager] EmbyConfig存在:', !!config.EmbyConfig);
|
||||
console.log('[EmbyManager] EmbyConfig.Sources存在:', !!config.EmbyConfig?.Sources);
|
||||
console.log('[EmbyManager] EmbyConfig.Sources是数组:', Array.isArray(config.EmbyConfig?.Sources));
|
||||
if (config.EmbyConfig?.Sources) {
|
||||
console.log('[EmbyManager] Sources长度:', config.EmbyConfig.Sources.length);
|
||||
console.log('[EmbyManager] Sources内容:', JSON.stringify(config.EmbyConfig.Sources, null, 2));
|
||||
}
|
||||
|
||||
// 如果是新格式(Sources数组)
|
||||
if (config.EmbyConfig?.Sources && Array.isArray(config.EmbyConfig.Sources)) {
|
||||
console.log('[EmbyManager] 使用新格式Sources,返回', config.EmbyConfig.Sources.length, '个源');
|
||||
return config.EmbyConfig.Sources;
|
||||
}
|
||||
|
||||
// 如果是旧格式(单源配置),转换为数组格式
|
||||
if (config.EmbyConfig?.ServerURL) {
|
||||
console.log('[EmbyManager] 使用旧格式配置,转换为数组');
|
||||
return [{
|
||||
key: 'default',
|
||||
name: 'Emby',
|
||||
@@ -78,7 +68,6 @@ class EmbyManager {
|
||||
}];
|
||||
}
|
||||
|
||||
console.log('[EmbyManager] 没有找到任何Emby配置,返回空数组');
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -141,18 +130,8 @@ class EmbyManager {
|
||||
* 获取所有启用的Emby源配置
|
||||
*/
|
||||
async getEnabledSources(): Promise<EmbySourceConfig[]> {
|
||||
console.log('[EmbyManager] getEnabledSources 被调用');
|
||||
const sources = await this.getSources();
|
||||
console.log('[EmbyManager] 获取到所有源:', sources.length, '个');
|
||||
|
||||
// 详细打印每个源的 enabled 字段
|
||||
sources.forEach((s, index) => {
|
||||
console.log(`[EmbyManager] 源 ${index}: key=${s.key}, name=${s.name}, enabled=${s.enabled}, enabled类型=${typeof s.enabled}, enabled===true: ${s.enabled === true}`);
|
||||
});
|
||||
|
||||
const enabledSources = sources.filter(s => s.enabled);
|
||||
console.log('[EmbyManager] 过滤后启用的源:', enabledSources.length, '个');
|
||||
return enabledSources;
|
||||
return sources.filter(s => s.enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user