From b0312ef4e08c920c1a9f7b1ab5a21c57bfefbe1c Mon Sep 17 00:00:00 2001 From: shinya Date: Thu, 31 Jul 2025 02:18:06 +0800 Subject: [PATCH] fix: ruyi fail --- VERSION.txt | 2 +- config.json | 2 +- src/lib/config.ts | 107 ++++++++++++++++++++++++--------------------- src/lib/version.ts | 2 +- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 363da30..6e6c67d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -20250731020402 \ No newline at end of file +20250731021807 \ No newline at end of file diff --git a/config.json b/config.json index 00db9fe..e2a9d11 100644 --- a/config.json +++ b/config.json @@ -12,7 +12,7 @@ "detail": "https://heimuer.tv" }, "ruyi": { - "api": "https://cj.rycjapi.com/api.php/provide/vod", + "api": "http://cj.rycjapi.com/api.php/provide/vod", "name": "如意资源" }, "bfzy": { diff --git a/src/lib/config.ts b/src/lib/config.ts index 44d2490..cc66d4f 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -95,22 +95,24 @@ async function initConfig() { if (adminConfig) { // 补全 SourceConfig - const existed = new Set( - (adminConfig.SourceConfig || []).map((s) => s.key) + const sourceConfigMap = new Map( + (adminConfig.SourceConfig || []).map((s) => [s.key, s]) ); + apiSiteEntries.forEach(([key, site]) => { - if (!existed.has(key)) { - adminConfig!.SourceConfig.push({ - key, - name: site.name, - api: site.api, - detail: site.detail, - from: 'config', - disabled: false, - }); - } + sourceConfigMap.set(key, { + key, + name: site.name, + api: site.api, + detail: site.detail, + from: 'config', + disabled: false, + }); }); + // 将 Map 转换回数组 + adminConfig.SourceConfig = Array.from(sourceConfigMap.values()); + // 检查现有源是否在 fileConfig.api_site 中,如果不在则标记为 custom const apiSiteKeys = new Set(apiSiteEntries.map(([key]) => key)); adminConfig.SourceConfig.forEach((source) => { @@ -125,31 +127,33 @@ async function initConfig() { } // 补全 CustomCategories - const existedCustomCategories = new Set( - adminConfig.CustomCategories.map((c) => c.query + c.type) + const customCategoriesMap = new Map( + adminConfig.CustomCategories.map((c) => [c.query + c.type, c]) ); + customCategories.forEach((category) => { - if (!existedCustomCategories.has(category.query + category.type)) { - adminConfig!.CustomCategories.push({ - name: category.name, - type: category.type, - query: category.query, - from: 'config', - disabled: false, - }); - } + customCategoriesMap.set(category.query + category.type, { + name: category.name, + type: category.type, + query: category.query, + from: 'config', + disabled: false, + }); }); // 检查现有 CustomCategories 是否在 fileConfig.custom_category 中,如果不在则标记为 custom const customCategoriesKeys = new Set( customCategories.map((c) => c.query + c.type) ); - adminConfig.CustomCategories.forEach((category) => { + customCategoriesMap.forEach((category) => { if (!customCategoriesKeys.has(category.query + category.type)) { category.from = 'custom'; } }); + // 将 Map 转换回数组 + adminConfig.CustomCategories = Array.from(customCategoriesMap.values()); + const existedUsers = new Set( (adminConfig.UserConfig.Users || []).map((u) => u.username) ); @@ -301,55 +305,61 @@ export async function getConfig(): Promise { // 合并文件中的源信息 fileConfig = runtimeConfig as unknown as ConfigFileStruct; const apiSiteEntries = Object.entries(fileConfig.api_site); - const existed = new Set((adminConfig.SourceConfig || []).map((s) => s.key)); + const sourceConfigMap = new Map( + (adminConfig.SourceConfig || []).map((s) => [s.key, s]) + ); + apiSiteEntries.forEach(([key, site]) => { - if (!existed.has(key)) { - adminConfig!.SourceConfig.push({ - key, - name: site.name, - api: site.api, - detail: site.detail, - from: 'config', - disabled: false, - }); - } + sourceConfigMap.set(key, { + key, + name: site.name, + api: site.api, + detail: site.detail, + from: 'config', + disabled: false, + }); }); // 检查现有源是否在 fileConfig.api_site 中,如果不在则标记为 custom const apiSiteKeys = new Set(apiSiteEntries.map(([key]) => key)); - adminConfig.SourceConfig.forEach((source) => { + sourceConfigMap.forEach((source) => { if (!apiSiteKeys.has(source.key)) { source.from = 'custom'; } }); + // 将 Map 转换回数组 + adminConfig.SourceConfig = Array.from(sourceConfigMap.values()); + // 补全 CustomCategories const customCategories = fileConfig.custom_category || []; - const existedCustomCategories = new Set( - adminConfig.CustomCategories.map((c) => c.query + c.type) + const customCategoriesMap = new Map( + adminConfig.CustomCategories.map((c) => [c.query + c.type, c]) ); + customCategories.forEach((category) => { - if (!existedCustomCategories.has(category.query + category.type)) { - adminConfig!.CustomCategories.push({ - name: category.name, - type: category.type, - query: category.query, - from: 'config', - disabled: false, - }); - } + 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) ); - adminConfig.CustomCategories.forEach((category) => { + customCategoriesMap.forEach((category) => { if (!customCategoriesKeys.has(category.query + category.type)) { category.from = 'custom'; } }); + // 将 Map 转换回数组 + adminConfig.CustomCategories = Array.from(customCategoriesMap.values()); + const ownerUser = process.env.USERNAME || ''; // 检查配置中的站长用户是否和 USERNAME 匹配,如果不匹配则降级为普通用户 let containOwner = false; @@ -406,7 +416,6 @@ export async function resetConfig() { fileConfig = runtimeConfig as unknown as ConfigFileStruct; } - // 从文件中获取源信息,用于补全源 const apiSiteEntries = Object.entries(fileConfig.api_site); const customCategories = fileConfig.custom_category || []; let allUsers = userNames.map((uname) => ({ diff --git a/src/lib/version.ts b/src/lib/version.ts index 4d24152..f73a112 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -2,7 +2,7 @@ 'use client'; -const CURRENT_VERSION = '20250731020402'; +const CURRENT_VERSION = '20250731021807'; // 版本检查结果枚举 export enum UpdateStatus {