修复私人影库报错导致搜索无结果
This commit is contained in:
@@ -55,6 +55,7 @@ export async function GET(request: NextRequest) {
|
||||
const embyPromise = hasEmby
|
||||
? Promise.race([
|
||||
(async () => {
|
||||
try {
|
||||
const { EmbyClient } = await import('@/lib/emby.client');
|
||||
const client = new EmbyClient(config.EmbyConfig!);
|
||||
const searchResult = await client.getItems({
|
||||
@@ -77,12 +78,16 @@ export async function GET(request: NextRequest) {
|
||||
type_name: item.Type === 'Movie' ? '电影' : '电视剧',
|
||||
douban_id: 0,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('[Search] 搜索 Emby 失败:', error);
|
||||
return [];
|
||||
}
|
||||
})(),
|
||||
new Promise<any[]>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Emby timeout')), 20000)
|
||||
),
|
||||
]).catch((error) => {
|
||||
console.error('[Search] 搜索 Emby 失败:', error);
|
||||
console.error('[Search] 搜索 Emby 超时:', error);
|
||||
return [];
|
||||
})
|
||||
: Promise.resolve([]);
|
||||
@@ -91,6 +96,7 @@ export async function GET(request: NextRequest) {
|
||||
const openlistPromise = hasOpenList
|
||||
? Promise.race([
|
||||
(async () => {
|
||||
try {
|
||||
const { getCachedMetaInfo, setCachedMetaInfo } = await import('@/lib/openlist-cache');
|
||||
const { getTMDBImageUrl } = await import('@/lib/tmdb.search');
|
||||
const { db } = await import('@/lib/db');
|
||||
@@ -130,12 +136,16 @@ export async function GET(request: NextRequest) {
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
} catch (error) {
|
||||
console.error('[Search] 搜索 OpenList 失败:', error);
|
||||
return [];
|
||||
}
|
||||
})(),
|
||||
new Promise<any[]>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('OpenList timeout')), 20000)
|
||||
),
|
||||
]).catch((error) => {
|
||||
console.error('[Search] 搜索 OpenList 失败:', error);
|
||||
console.error('[Search] 搜索 OpenList 超时:', error);
|
||||
return [];
|
||||
})
|
||||
: Promise.resolve([]);
|
||||
|
||||
@@ -93,6 +93,7 @@ export async function GET(request: NextRequest) {
|
||||
if (hasEmby) {
|
||||
Promise.race([
|
||||
(async () => {
|
||||
try {
|
||||
const { EmbyClient } = await import('@/lib/emby.client');
|
||||
const client = new EmbyClient(config.EmbyConfig!);
|
||||
const searchResult = await client.getItems({
|
||||
@@ -115,6 +116,10 @@ export async function GET(request: NextRequest) {
|
||||
type_name: item.Type === 'Movie' ? '电影' : '电视剧',
|
||||
douban_id: 0,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('[Search WS] 搜索 Emby 失败:', error);
|
||||
return [];
|
||||
}
|
||||
})(),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Emby timeout')), 20000)
|
||||
@@ -140,17 +145,17 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('[Search WS] 搜索 Emby 失败:', error);
|
||||
console.error('[Search WS] 搜索 Emby 超时:', error);
|
||||
completedSources++;
|
||||
if (!streamClosed) {
|
||||
const errorEvent = `data: ${JSON.stringify({
|
||||
type: 'source_error',
|
||||
const sourceEvent = `data: ${JSON.stringify({
|
||||
type: 'source_result',
|
||||
source: 'emby',
|
||||
sourceName: 'Emby',
|
||||
error: error instanceof Error ? error.message : '搜索失败',
|
||||
results: [],
|
||||
timestamp: Date.now()
|
||||
})}\n\n`;
|
||||
safeEnqueue(encoder.encode(errorEvent));
|
||||
safeEnqueue(encoder.encode(sourceEvent));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -159,6 +164,7 @@ export async function GET(request: NextRequest) {
|
||||
if (hasOpenList) {
|
||||
Promise.race([
|
||||
(async () => {
|
||||
try {
|
||||
const { getCachedMetaInfo, setCachedMetaInfo } = await import('@/lib/openlist-cache');
|
||||
const { getTMDBImageUrl } = await import('@/lib/tmdb.search');
|
||||
const { db } = await import('@/lib/db');
|
||||
@@ -198,6 +204,10 @@ export async function GET(request: NextRequest) {
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
} catch (error) {
|
||||
console.error('[Search WS] 搜索 OpenList 失败:', error);
|
||||
return [];
|
||||
}
|
||||
})(),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('OpenList timeout')), 20000)
|
||||
@@ -223,17 +233,17 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('[Search WS] 搜索 OpenList 失败:', error);
|
||||
console.error('[Search WS] 搜索 OpenList 超时:', error);
|
||||
completedSources++;
|
||||
if (!streamClosed) {
|
||||
const errorEvent = `data: ${JSON.stringify({
|
||||
type: 'source_error',
|
||||
const sourceEvent = `data: ${JSON.stringify({
|
||||
type: 'source_result',
|
||||
source: 'openlist',
|
||||
sourceName: '私人影库',
|
||||
error: error instanceof Error ? error.message : '搜索失败',
|
||||
results: [],
|
||||
timestamp: Date.now()
|
||||
})}\n\n`;
|
||||
safeEnqueue(encoder.encode(errorEvent));
|
||||
safeEnqueue(encoder.encode(sourceEvent));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user