mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-03-04 18:37:30 +08:00
feat: make get config sync
This commit is contained in:
@@ -44,6 +44,10 @@ let fileConfig: ConfigFileStruct;
|
||||
let cachedConfig: AdminConfig;
|
||||
|
||||
async function initConfig() {
|
||||
if (cachedConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.DOCKER_ENV === 'true') {
|
||||
// 这里用 eval("require") 避开静态分析,防止 Edge Runtime 打包时报 "Can't resolve 'fs'"
|
||||
// 在实际 Node.js 运行时才会执行到,因此不会影响 Edge 环境。
|
||||
@@ -216,9 +220,8 @@ async function initConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
initConfig();
|
||||
|
||||
export function getConfig(): AdminConfig {
|
||||
export async function getConfig(): Promise<AdminConfig> {
|
||||
await initConfig();
|
||||
return cachedConfig;
|
||||
}
|
||||
|
||||
@@ -283,13 +286,13 @@ export async function resetConfig() {
|
||||
cachedConfig.SourceConfig = adminConfig.SourceConfig;
|
||||
}
|
||||
|
||||
export function getCacheTime(): number {
|
||||
const config = getConfig();
|
||||
export async function getCacheTime(): Promise<number> {
|
||||
const config = await getConfig();
|
||||
return config.SiteConfig.SiteInterfaceCacheTime || 7200;
|
||||
}
|
||||
|
||||
export function getAvailableApiSites(): ApiSite[] {
|
||||
const config = getConfig();
|
||||
export async function getAvailableApiSites(): Promise<ApiSite[]> {
|
||||
const config = await getConfig();
|
||||
return config.SourceConfig.filter((s) => !s.disabled).map((s) => ({
|
||||
key: s.key,
|
||||
name: s.name,
|
||||
|
||||
@@ -2,9 +2,6 @@ import { API_CONFIG, ApiSite, getConfig } from '@/lib/config';
|
||||
import { SearchResult } from '@/lib/types';
|
||||
import { cleanHtmlTags } from '@/lib/utils';
|
||||
|
||||
const config = getConfig();
|
||||
const MAX_SEARCH_PAGES: number = config.SiteConfig.SearchDownstreamMaxPage;
|
||||
|
||||
interface ApiSearchItem {
|
||||
vod_id: string;
|
||||
vod_name: string;
|
||||
@@ -93,6 +90,9 @@ export async function searchFromApi(
|
||||
};
|
||||
});
|
||||
|
||||
const config = await getConfig();
|
||||
const MAX_SEARCH_PAGES: number = config.SiteConfig.SearchDownstreamMaxPage;
|
||||
|
||||
// 获取总页数
|
||||
const pageCount = data.pagecount || 1;
|
||||
// 确定需要获取的额外页数
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function fetchVideoDetail({
|
||||
fallbackTitle = '',
|
||||
}: FetchVideoDetailOptions): Promise<SearchResult> {
|
||||
// 优先通过搜索接口查找精确匹配
|
||||
const apiSites = getAvailableApiSites();
|
||||
const apiSites = await getAvailableApiSites();
|
||||
const apiSite = apiSites.find((site) => site.key === source);
|
||||
if (!apiSite) {
|
||||
throw new Error('无效的API来源');
|
||||
|
||||
Reference in New Issue
Block a user