2 Commits

Author SHA1 Message Date
shinya
00341d8abc fix: fix overwrite source disable config 2025-08-04 19:07:50 +08:00
shinya
a26f19f3d5 fix: overwrite categories with file config when in d1 and upstash 2025-08-04 18:57:36 +08:00
3 changed files with 28 additions and 37 deletions

View File

@@ -1 +1 @@
20250801133915
20250804190750

View File

@@ -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 匹配,如果不匹配则降级为普通用户

View File

@@ -2,7 +2,7 @@
'use client';
const CURRENT_VERSION = '20250801133915';
const CURRENT_VERSION = '20250804190750';
// 版本检查结果枚举
export enum UpdateStatus {