feat: 更新搜索结果处理逻辑,支持合并常规和成人内容结果,兼容旧格式
This commit is contained in:
+21
-9
@@ -1,17 +1,29 @@
|
||||
{
|
||||
"cache_time": 7200,
|
||||
"api_site": {
|
||||
"example_test": {
|
||||
"api": "https://example.com/api.php/provide/vod",
|
||||
"name": "示例视频源",
|
||||
"detail": "https://example.com",
|
||||
"okzy": {
|
||||
"api": "https://okzy.tv/api.php/provide/vod",
|
||||
"name": "OK资源",
|
||||
"detail": "https://okzy.tv/api.php/provide/vod/?ac=detail&ids={ids}",
|
||||
"is_adult": false
|
||||
},
|
||||
"adult_example": {
|
||||
"api": "https://adult-example.com/api.php/provide/vod",
|
||||
"name": "成人内容源(仅供示例)",
|
||||
"detail": "https://adult-example.com",
|
||||
"is_adult": true
|
||||
"hnzy": {
|
||||
"api": "https://www.hongniuzy.com/inc/api.php",
|
||||
"name": "红牛资源",
|
||||
"detail": "https://www.hongniuzy.com/inc/api.php?ac=detail&ids={ids}",
|
||||
"is_adult": false
|
||||
},
|
||||
"ffzy": {
|
||||
"api": "https://cj.ffzyapi.com/api.php/provide/vod",
|
||||
"name": "非凡资源",
|
||||
"detail": "https://cj.ffzyapi.com/api.php/provide/vod/?ac=detail&ids={ids}",
|
||||
"is_adult": false
|
||||
},
|
||||
"lzzy": {
|
||||
"api": "https://api.lzapi.com/api.php/provide/vod",
|
||||
"name": "量子资源",
|
||||
"detail": "https://api.lzapi.com/api.php/provide/vod/?ac=detail&ids={ids}",
|
||||
"is_adult": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,12 @@ export async function GET(request: Request) {
|
||||
|
||||
// 获取常规资源站
|
||||
const regularSites = await getAvailableApiSites(true); // 总是过滤成人内容
|
||||
console.log('搜索API - 获取到的常规站点数量:', regularSites.length);
|
||||
console.log('搜索API - 常规站点列表:', regularSites.map(s => s.name).join(', '));
|
||||
|
||||
const regularSearchPromises = regularSites.map((site) => searchFromApi(site, query));
|
||||
const regularResults = (await Promise.all(regularSearchPromises)).flat();
|
||||
console.log('搜索API - 常规搜索结果数量:', regularResults.length);
|
||||
|
||||
let adultResults: unknown[] = [];
|
||||
|
||||
|
||||
+15
-1
@@ -505,8 +505,22 @@ function PlayPageClient() {
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
// 处理新的搜索结果格式:合并 regular_results 和 adult_results
|
||||
let allResults: SearchResult[] = [];
|
||||
if (data.regular_results && Array.isArray(data.regular_results)) {
|
||||
allResults = allResults.concat(data.regular_results);
|
||||
}
|
||||
if (data.adult_results && Array.isArray(data.adult_results)) {
|
||||
allResults = allResults.concat(data.adult_results);
|
||||
}
|
||||
|
||||
// 兼容旧格式(如果有的话)
|
||||
if (data.results && Array.isArray(data.results)) {
|
||||
allResults = data.results;
|
||||
}
|
||||
|
||||
// 处理搜索结果,根据规则过滤
|
||||
const results = data.results.filter(
|
||||
const results = allResults.filter(
|
||||
(result: SearchResult) =>
|
||||
result.title.replaceAll(' ', '').toLowerCase() ===
|
||||
videoTitleRef.current.replaceAll(' ', '').toLowerCase() &&
|
||||
|
||||
+10
-3
@@ -185,16 +185,23 @@ function SearchPageClient() {
|
||||
);
|
||||
const data = await response.json();
|
||||
|
||||
// 如果返回了分组结果,我们需要处理这种格式
|
||||
if (data.grouped) {
|
||||
// 处理新的搜索结果格式
|
||||
if (data.regular_results || data.adult_results) {
|
||||
// 处理分组结果
|
||||
setGroupedResults({
|
||||
regular: data.regular_results || [],
|
||||
adult: data.adult_results || []
|
||||
});
|
||||
setSearchResults([...(data.regular_results || []), ...(data.adult_results || [])]);
|
||||
} else if (data.grouped) {
|
||||
// 兼容旧的分组格式
|
||||
setGroupedResults({
|
||||
regular: data.regular || [],
|
||||
adult: data.adult || []
|
||||
});
|
||||
setSearchResults([...(data.regular || []), ...(data.adult || [])]);
|
||||
} else {
|
||||
// 处理普通结果
|
||||
// 兼容旧的普通结果格式
|
||||
setGroupedResults(null);
|
||||
setSearchResults(data.results || []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user