feat: add NEXT_PUBLIC_SEARCH_MAX_PAGE & NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT

This commit is contained in:
shinya
2025-06-26 13:57:17 +08:00
parent 1d75e85264
commit 1e9e8fb07a
4 changed files with 21 additions and 12 deletions

View File

@@ -128,11 +128,13 @@ Pull Bot 会反复触发无效的 PR 和垃圾邮件,严重干扰项目维护
## 环境变量
| 变量 | 说明 | 可选值 | 默认值 |
| --------------------------- | ---------------------------------- | ---------------------------------------------------------------- | ------------ |
| PASSWORD | 实例访问密码,留空则不启用密码保护 | 任意字符串 | (空) |
| NEXT_PUBLIC_STORAGE_TYPE | 播放记录/收藏的存储方式 | localstorage本地浏览器存储、database后端数据库暂不支持 | localstorage |
| NEXT_PUBLIC_DISABLE_BLOCKAD | 禁用智能去广告功能 | true / false | false |
| 变量 | 说明 | 可选值 | 默认值 |
| ----------------------------------- | ---------------------------------- | ---------------------------------------------------------------- | ------------ |
| PASSWORD | 实例访问密码,留空则不启用密码保护 | 任意字符串 | (空) |
| NEXT_PUBLIC_STORAGE_TYPE | 播放记录/收藏的存储方式 | localstorage本地浏览器存储、database后端数据库暂不支持 | localstorage |
| NEXT_PUBLIC_DISABLE_BLOCKAD | 禁用智能去广告功能 | true / false | false |
| NEXT_PUBLIC_SEARCH_MAX_PAGE | 搜索接口可拉取的最大页数 | 1-50 | 5 |
| NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT | 搜索结果默认是否按标题和年份聚合 | true / false | true |
## 配置说明

View File

@@ -3,6 +3,10 @@ import { NextResponse } from 'next/server';
import { API_CONFIG, ApiSite, getApiSites, getCacheTime } from '@/lib/config';
import { cleanHtmlTags } from '@/lib/utils';
// 根据环境变量决定最大搜索页数,默认 5
const MAX_SEARCH_PAGES: number =
Number(process.env.NEXT_PUBLIC_SEARCH_MAX_PAGE) || 5;
export interface SearchResult {
id: string;
title: string;
@@ -104,10 +108,7 @@ async function searchFromApi(
// 获取总页数
const pageCount = data.pagecount || 1;
// 确定需要获取的额外页数
const pagesToFetch = Math.min(
pageCount - 1,
API_CONFIG.search.maxPages - 1
);
const pagesToFetch = Math.min(pageCount - 1, MAX_SEARCH_PAGES - 1);
// 如果有额外页数,获取更多页的结果
if (pagesToFetch > 0) {

View File

@@ -41,8 +41,15 @@ function SearchPageClient() {
const [searchResults, setSearchResults] = useState<SearchResult[]>([]);
const searchInputRef = useRef<HTMLInputElement>(null);
// 视图模式:聚合(agg) 或 全部(all)
const [viewMode, setViewMode] = useState<'agg' | 'all'>('agg');
// 视图模式:聚合(agg) 或 全部(all),默认值由环境变量 NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT 决定
const [viewMode, setViewMode] = useState<'agg' | 'all'>(() => {
const envVal = process.env.NEXT_PUBLIC_AGGREGATE_SEARCH_RESULT;
// 默认聚合('agg')。当显式设置为 'false' 或 '0' 时使用 'all'
if (envVal === 'false' || envVal === '0') {
return 'all';
}
return 'agg';
});
// 聚合后的结果(按标题和年份分组)
const aggregatedResults = useMemo(() => {

View File

@@ -36,7 +36,6 @@ export const API_CONFIG = {
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
Accept: 'application/json',
},
maxPages: 50,
},
detail: {
path: '?ac=videolist&ids=',