From 07d5a913f0588c6eb199a6a0bfcbb1bb93b36db0 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 9 Feb 2025 20:58:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=8C=E6=AD=A5=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/products/cron-sync-artifacts.js | 35 ++++++++++++++++----- backend/src/restful/sync.js | 34 +++++++++++++++----- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/backend/package.json b/backend/package.json index a191278..39f8f7b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.30", + "version": "2.16.31", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/products/cron-sync-artifacts.js b/backend/src/products/cron-sync-artifacts.js index bdf1122..004440e 100644 --- a/backend/src/products/cron-sync-artifacts.js +++ b/backend/src/products/cron-sync-artifacts.js @@ -84,6 +84,7 @@ async function doSync() { const files = {}; try { + const valid = []; const invalid = []; const allSubs = $.read(SUBS_KEY); const allCols = $.read(COLLECTIONS_KEY); @@ -156,19 +157,26 @@ async function doSync() { files[encodeURIComponent(artifact.name)] = { content: output, }; + + valid.push(artifact.name); } } catch (e) { $.error( - `同步配置 ${artifact.name} 发生错误: ${e.message ?? e}`, + `生成同步配置 ${artifact.name} 发生错误: ${ + e.message ?? e + }`, ); invalid.push(artifact.name); } }), ); - if (invalid.length > 0) { + $.info(`${valid.length} 个同步配置生成成功: ${valid.join(', ')}`); + $.info(`${invalid.length} 个同步配置生成失败: ${invalid.join(', ')}`); + + if (valid.length === 0) { throw new Error( - `同步配置 ${invalid.join(', ')} 发生错误 详情请查看日志`, + `同步配置 ${invalid.join(', ')} 生成失败 详情请查看日志`, ); } @@ -184,7 +192,11 @@ async function doSync() { $.info(JSON.stringify(body, null, 2)); for (const artifact of allArtifacts) { - if (artifact.sync) { + if ( + artifact.sync && + artifact.source && + valid.includes(artifact.name) + ) { artifact.updated = new Date().getTime(); // extract real url from gist let files = body.files; @@ -212,9 +224,18 @@ async function doSync() { } $.write(allArtifacts, ARTIFACTS_KEY); - $.notify('🌍 Sub-Store', '全部订阅同步成功!'); + $.info('上传配置成功'); + + if (invalid.length > 0) { + $.notify( + '🌍 Sub-Store', + `同步配置成功 ${valid.length} 个, 失败 ${invalid.length} 个, 详情请查看日志`, + ); + } else { + $.notify('🌍 Sub-Store', '同步配置完成'); + } } catch (e) { - $.notify('🌍 Sub-Store', '同步订阅失败', `原因:${e.message ?? e}`); - $.error(`无法同步订阅配置到 Gist,原因:${e}`); + $.notify('🌍 Sub-Store', '同步配置失败', `原因:${e.message ?? e}`); + $.error(`无法同步配置到 Gist,原因:${e}`); } } diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index dea1c31..4c0c369 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -540,6 +540,7 @@ async function syncArtifacts() { const files = {}; try { + const valid = []; const invalid = []; const allSubs = $.read(SUBS_KEY); const allCols = $.read(COLLECTIONS_KEY); @@ -614,19 +615,26 @@ async function syncArtifacts() { files[encodeURIComponent(artifact.name)] = { content: output, }; + + valid.push(artifact.name); } } catch (e) { $.error( - `同步配置 ${artifact.name} 发生错误: ${e.message ?? e}`, + `生成同步配置 ${artifact.name} 发生错误: ${ + e.message ?? e + }`, ); invalid.push(artifact.name); } }), ); - if (invalid.length > 0) { + $.info(`${valid.length} 个同步配置生成成功: ${valid.join(', ')}`); + $.info(`${invalid.length} 个同步配置生成失败: ${invalid.join(', ')}`); + + if (valid.length === 0) { throw new Error( - `同步配置 ${invalid.join(', ')} 发生错误 详情请查看日志`, + `同步配置 ${invalid.join(', ')} 生成失败 详情请查看日志`, ); } @@ -643,7 +651,11 @@ async function syncArtifacts() { $.info(JSON.stringify(body, null, 2)); for (const artifact of allArtifacts) { - if (artifact.sync) { + if ( + artifact.sync && + artifact.source && + valid.includes(artifact.name) + ) { artifact.updated = new Date().getTime(); // extract real url from gist let files = body.files; @@ -671,9 +683,17 @@ async function syncArtifacts() { } $.write(allArtifacts, ARTIFACTS_KEY); - $.info('全部订阅同步成功!'); + $.info('上传配置成功'); + + if (invalid.length > 0) { + throw new Error( + `同步配置成功 ${valid.length} 个, 失败 ${invalid.length} 个, 详情请查看日志`, + ); + } else { + $.info(`同步配置成功 ${valid.length} 个`); + } } catch (e) { - $.error(`同步订阅失败,原因:${e.message ?? e}`); + $.error(`同步配置失败,原因:${e.message ?? e}`); throw e; } } @@ -683,7 +703,7 @@ async function syncAllArtifacts(_, res) { await syncArtifacts(); success(res); } catch (e) { - $.error(`同步订阅失败,原因:${e.message ?? e}`); + $.error(`同步配置失败,原因:${e.message ?? e}`); failed( res, new InternalServerError(