From a8ea7bec34492921017723116a74f05d48a2e0b3 Mon Sep 17 00:00:00 2001 From: shenmo Date: Thu, 16 Jul 2026 14:27:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(submitter):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=89=E6=9E=B6=E6=9E=84=E8=8E=B7=E5=8F=96?= =?UTF-8?q?CDN=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 提取公共的CDN分类获取函数,增加 fallback 兜底逻辑 2. 新增支持amd64、arm64等更多架构类型 3. 为每个架构单独加载对应的分类列表,适配不同架构的分类差异 4. 更新日志打印参数,更清晰展示各架构的分类数量 --- electron/main/backend/submitter.ts | 94 +++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/electron/main/backend/submitter.ts b/electron/main/backend/submitter.ts index 43625123..f1cccc45 100644 --- a/electron/main/backend/submitter.ts +++ b/electron/main/backend/submitter.ts @@ -641,6 +641,61 @@ export function registerSubmitterHandlers( } }); + const FALLBACK_CATEGORIES = [ + "chat", + "development", + "games", + "image_graphics", + "music", + "network", + "office", + "others", + "reading", + "themes", + "tools", + "video", + ]; + + async function fetchCategoriesFromCdn( + baseUrl: string, + arch: string, + ): Promise { + const url = `${baseUrl}/${arch}/categories.json`; + logger.info({ url }, "[Submitter] Fetching categories from CDN"); + try { + const response = await fetch(url, { + headers: { "User-Agent": getUserAgent() }, + }); + if (!response.ok) { + logger.warn( + { status: response.status, arch }, + "[Submitter] Failed to fetch categories.json, using fallback", + ); + return FALLBACK_CATEGORIES; + } + const json = await response.json(); + if (json && typeof json === "object" && !Array.isArray(json)) { + const keys = Object.keys(json); + logger.info( + { arch, categories: keys, count: keys.length }, + "[Submitter] Categories loaded from CDN", + ); + return keys.length > 0 ? keys : FALLBACK_CATEGORIES; + } + logger.warn( + { arch }, + "[Submitter] Unexpected categories.json format, using fallback", + ); + return FALLBACK_CATEGORIES; + } catch (err) { + logger.warn( + { err, arch }, + "[Submitter] Error fetching categories.json, using fallback", + ); + return FALLBACK_CATEGORIES; + } + } + ipcMain.handle( "search-history-app", async (_event, pkgname: string, useMirror = false) => { @@ -648,34 +703,43 @@ export function registerSubmitterHandlers( const baseUrl = useMirror ? "https://mirrors.sdu.edu.cn/spark-store" : "https://spk-json.spark-app.store"; - const storeArchs = ["store", "aarch64-store", "loong64-store"]; - const categories = [ - "chat", - "development", - "games", - "image_graphics", - "music", - "network", - "office", - "others", - "reading", - "themes", - "tools", - "video", + const storeArchs = [ + "amd64-store", + "arm64-store", + "loong64-store", + "amd64-apm", + "arm64-apm", + "loong64-apm", ]; const results: HistoryAppInfo[] = []; + // 为每个架构目录获取各自的分类列表(不同目录可能有不同分类,如 apm-extensions 只在 *-apm 下有) + const archCategoriesMap = new Map(); + for (const arch of storeArchs) { + const cats = await fetchCategoriesFromCdn(baseUrl, arch); + archCategoriesMap.set(arch, cats); + } + logger.info( "[Submitter] ============== SEARCH HISTORY APP START ==============", ); logger.info( - { pkgname, useMirror, baseUrl, storeArchs, categories }, + { + pkgname, + useMirror, + baseUrl, + storeArchs, + archCategoryCounts: Array.from(archCategoriesMap.entries()).map( + ([a, c]) => ({ arch: a, categoryCount: c.length }), + ), + }, "[Submitter] Search parameters", ); const allPromises: Promise[] = []; for (const arch of storeArchs) { + const categories = archCategoriesMap.get(arch) || FALLBACK_CATEGORIES; for (const category of categories) { const url = `${baseUrl}/${arch}/${category}/${pkgname}/app.json`; logger.info(