增加视频特殊源配置功能
This commit is contained in:
@@ -85,6 +85,7 @@ export interface AdminConfig {
|
||||
permissions?: string[];
|
||||
}[];
|
||||
};
|
||||
SpecialSourceApis?: string[]; // 特殊源 key 列表,默认对普通入口隐藏
|
||||
SourceConfig: {
|
||||
key: string;
|
||||
name: string;
|
||||
|
||||
+42
-2
@@ -47,6 +47,8 @@ interface ConfigFileStruct {
|
||||
lives?: {
|
||||
[key: string]: LiveCfg;
|
||||
};
|
||||
special_source_apis?: string[];
|
||||
specialSourceApis?: string[];
|
||||
}
|
||||
|
||||
export const API_CONFIG = {
|
||||
@@ -120,6 +122,18 @@ export function refineConfig(adminConfig: AdminConfig): AdminConfig {
|
||||
// 将 Map 转换回数组
|
||||
adminConfig.SourceConfig = Array.from(currentApiSites.values());
|
||||
|
||||
const specialApisFromFile = Array.isArray(fileConfig.special_source_apis)
|
||||
? fileConfig.special_source_apis
|
||||
: Array.isArray(fileConfig.specialSourceApis)
|
||||
? fileConfig.specialSourceApis
|
||||
: undefined;
|
||||
if (specialApisFromFile) {
|
||||
const sourceKeys = new Set(adminConfig.SourceConfig.map((source) => source.key));
|
||||
adminConfig.SpecialSourceApis = Array.from(new Set(specialApisFromFile)).filter((key) =>
|
||||
sourceKeys.has(key)
|
||||
);
|
||||
}
|
||||
|
||||
// 覆盖 CustomCategories
|
||||
const customCategoriesFromFile = fileConfig.custom_category || [];
|
||||
const currentCustomCategories = new Map(
|
||||
@@ -316,6 +330,11 @@ async function getInitConfig(
|
||||
SourceConfig: [],
|
||||
CustomCategories: [],
|
||||
LiveConfig: [],
|
||||
SpecialSourceApis: Array.isArray(cfgFile.special_source_apis)
|
||||
? cfgFile.special_source_apis
|
||||
: Array.isArray(cfgFile.specialSourceApis)
|
||||
? cfgFile.specialSourceApis
|
||||
: [],
|
||||
};
|
||||
|
||||
// 用户信息已迁移到新版数据库,不再填充 UserConfig.Users
|
||||
@@ -581,6 +600,12 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
||||
if (!adminConfig.LiveConfig || !Array.isArray(adminConfig.LiveConfig)) {
|
||||
adminConfig.LiveConfig = [];
|
||||
}
|
||||
if (
|
||||
!adminConfig.SpecialSourceApis ||
|
||||
!Array.isArray(adminConfig.SpecialSourceApis)
|
||||
) {
|
||||
adminConfig.SpecialSourceApis = [];
|
||||
}
|
||||
adminConfig.LiveRefreshIntervalHours = normalizeLiveRefreshIntervalHours(
|
||||
adminConfig.LiveRefreshIntervalHours
|
||||
);
|
||||
@@ -631,6 +656,11 @@ export function configSelfCheck(adminConfig: AdminConfig): AdminConfig {
|
||||
return true;
|
||||
});
|
||||
|
||||
const validSourceKeys = new Set(adminConfig.SourceConfig.map((source) => source.key));
|
||||
adminConfig.SpecialSourceApis = Array.from(
|
||||
new Set((adminConfig.SpecialSourceApis || []).filter((key) => validSourceKeys.has(key)))
|
||||
);
|
||||
|
||||
// 自定义分类去重
|
||||
const seenCustomCategoryKeys = new Set<string>();
|
||||
adminConfig.CustomCategories = adminConfig.CustomCategories.filter(
|
||||
@@ -963,9 +993,19 @@ export async function getCacheTime(): Promise<number> {
|
||||
return config.SiteConfig.SiteInterfaceCacheTime || 7200;
|
||||
}
|
||||
|
||||
export async function getAvailableApiSites(user?: string): Promise<ApiSite[]> {
|
||||
export async function getAvailableApiSites(
|
||||
user?: string,
|
||||
includeSpecialSources = false
|
||||
): Promise<ApiSite[]> {
|
||||
const config = await getConfig();
|
||||
const allApiSites = config.SourceConfig.filter((s) => !s.disabled);
|
||||
const specialSourceSet = new Set(config.SpecialSourceApis || []);
|
||||
const filterSpecialSources = <T extends { key: string }>(sites: T[]): T[] =>
|
||||
includeSpecialSources
|
||||
? sites
|
||||
: sites.filter((site) => !specialSourceSet.has(site.key));
|
||||
const allApiSites = filterSpecialSources(
|
||||
config.SourceConfig.filter((s) => !s.disabled)
|
||||
);
|
||||
|
||||
if (!user) {
|
||||
return allApiSites;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
export const SPECIAL_SOURCE_STORAGE_KEY = 'specialSourcesEnabled';
|
||||
|
||||
export function isSpecialSourcesEnabledOnDevice(): boolean {
|
||||
if (typeof window === 'undefined') return false;
|
||||
return localStorage.getItem(SPECIAL_SOURCE_STORAGE_KEY) === '1';
|
||||
}
|
||||
|
||||
export function setSpecialSourcesEnabledOnDevice(enabled: boolean) {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (enabled) {
|
||||
localStorage.setItem(SPECIAL_SOURCE_STORAGE_KEY, '1');
|
||||
} else {
|
||||
localStorage.removeItem(SPECIAL_SOURCE_STORAGE_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
export function appendSpecialSourceParam(url: string): string {
|
||||
if (!isSpecialSourcesEnabledOnDevice()) return url;
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
return `${url}${separator}special=1`;
|
||||
}
|
||||
|
||||
export function appendSpecialSourceSearchParam(params: URLSearchParams) {
|
||||
if (isSpecialSourcesEnabledOnDevice()) {
|
||||
params.set('special', '1');
|
||||
}
|
||||
return params;
|
||||
}
|
||||
Reference in New Issue
Block a user