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