|
|
|
|
@@ -316,14 +316,24 @@ export async function getConfig(): Promise<AdminConfig> {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
apiSiteEntries.forEach(([key, site]) => {
|
|
|
|
|
sourceConfigMap.set(key, {
|
|
|
|
|
key,
|
|
|
|
|
name: site.name,
|
|
|
|
|
api: site.api,
|
|
|
|
|
detail: site.detail,
|
|
|
|
|
from: 'config',
|
|
|
|
|
disabled: false,
|
|
|
|
|
});
|
|
|
|
|
const existingSource = sourceConfigMap.get(key);
|
|
|
|
|
if (existingSource) {
|
|
|
|
|
// 如果已存在,只覆盖 name、api、detail 和 from
|
|
|
|
|
existingSource.name = site.name;
|
|
|
|
|
existingSource.api = site.api;
|
|
|
|
|
existingSource.detail = site.detail;
|
|
|
|
|
existingSource.from = 'config';
|
|
|
|
|
} else {
|
|
|
|
|
// 如果不存在,创建新条目
|
|
|
|
|
sourceConfigMap.set(key, {
|
|
|
|
|
key,
|
|
|
|
|
name: site.name,
|
|
|
|
|
api: site.api,
|
|
|
|
|
detail: site.detail,
|
|
|
|
|
from: 'config',
|
|
|
|
|
disabled: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 检查现有源是否在 fileConfig.api_site 中,如果不在则标记为 custom
|
|
|
|
|
@@ -337,34 +347,15 @@ export async function getConfig(): Promise<AdminConfig> {
|
|
|
|
|
// 将 Map 转换回数组
|
|
|
|
|
adminConfig.SourceConfig = Array.from(sourceConfigMap.values());
|
|
|
|
|
|
|
|
|
|
// 补全 CustomCategories
|
|
|
|
|
// 覆盖 CustomCategories
|
|
|
|
|
const customCategories = fileConfig.custom_category || [];
|
|
|
|
|
const customCategoriesMap = new Map(
|
|
|
|
|
adminConfig.CustomCategories.map((c) => [c.query + c.type, c])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
customCategories.forEach((category) => {
|
|
|
|
|
customCategoriesMap.set(category.query + category.type, {
|
|
|
|
|
name: category.name,
|
|
|
|
|
type: category.type,
|
|
|
|
|
query: category.query,
|
|
|
|
|
from: 'config',
|
|
|
|
|
disabled: false,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 检查现有 CustomCategories 是否在 fileConfig.custom_categories 中,如果不在则标记为 custom
|
|
|
|
|
const customCategoriesKeys = new Set(
|
|
|
|
|
customCategories.map((c) => c.query + c.type)
|
|
|
|
|
);
|
|
|
|
|
customCategoriesMap.forEach((category) => {
|
|
|
|
|
if (!customCategoriesKeys.has(category.query + category.type)) {
|
|
|
|
|
category.from = 'custom';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 将 Map 转换回数组
|
|
|
|
|
adminConfig.CustomCategories = Array.from(customCategoriesMap.values());
|
|
|
|
|
adminConfig.CustomCategories = customCategories.map((category) => ({
|
|
|
|
|
name: category.name,
|
|
|
|
|
type: category.type,
|
|
|
|
|
query: category.query,
|
|
|
|
|
from: 'config',
|
|
|
|
|
disabled: false,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const ownerUser = process.env.USERNAME || '';
|
|
|
|
|
// 检查配置中的站长用户是否和 USERNAME 匹配,如果不匹配则降级为普通用户
|
|
|
|
|
|