diff --git a/backend/package.json b/backend/package.json index a412b77..f049ce6 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.317", + "version": "2.14.318", "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 598dbce..a811d30 100644 --- a/backend/src/products/cron-sync-artifacts.js +++ b/backend/src/products/cron-sync-artifacts.js @@ -11,17 +11,63 @@ import { syncToGist } from '@/restful/artifacts'; import { findByName } from '@/utils/database'; !(async function () { - const settings = $.read(SETTINGS_KEY); - // if GitHub token is not configured - if (!settings.githubUser || !settings.gistToken) return; + let arg; + if (typeof $argument != 'undefined') { + arg = Object.fromEntries( + // eslint-disable-next-line no-undef + $argument.split('&').map((item) => item.split('=')), + ); + } else { + arg = {}; + } + let sub_names = (arg?.subscription ?? arg?.sub ?? '') + .split(/,|,/g) + .map((i) => i.trim()) + .filter((i) => i.length > 0); + let col_names = (arg?.collection ?? arg?.col ?? '') + .split(/,|,/g) + .map((i) => i.trim()) + .filter((i) => i.length > 0); + if (sub_names.length > 0 || col_names.length > 0) { + if (sub_names.length > 0) + await produceArtifacts(sub_names, 'subscription'); + if (col_names.length > 0) + await produceArtifacts(col_names, 'collection'); + } else { + const settings = $.read(SETTINGS_KEY); + // if GitHub token is not configured + if (!settings.githubUser || !settings.gistToken) return; - const artifacts = $.read(ARTIFACTS_KEY); - if (!artifacts || artifacts.length === 0) return; + const artifacts = $.read(ARTIFACTS_KEY); + if (!artifacts || artifacts.length === 0) return; - const shouldSync = artifacts.some((artifact) => artifact.sync); - if (shouldSync) await doSync(); + const shouldSync = artifacts.some((artifact) => artifact.sync); + if (shouldSync) await doSync(); + } })().finally(() => $.done()); +async function produceArtifacts(names, type) { + try { + if (names.length > 0) { + $.info(`produceArtifacts ${type} 开始: ${names.join(', ')}`); + await Promise.all( + names.map(async (name) => { + try { + await produceArtifact({ + type, + name, + }); + } catch (e) { + $.error(`${type} ${name} error: ${e.message ?? e}`); + } + }), + ); + $.info(`produceArtifacts ${type} 完成: ${names.join(', ')}`); + } + } catch (e) { + $.error(`produceArtifacts error: ${e.message ?? e}`); + } +} async function doSync() { console.log( ` diff --git a/config/Surge-Beta.sgmodule b/config/Surge-Beta.sgmodule index 3a725b9..a2d7df8 100644 --- a/config/Surge-Beta.sgmodule +++ b/config/Surge-Beta.sgmodule @@ -1,8 +1,8 @@ #!name=Sub-Store(β) #!desc=支持 Surge 正式版的参数设置功能. 测落地功能 ability: http-client-policy, 同步配置的定时 cronexp: 55 23 * * * #!category=订阅管理 -#!arguments=ability:http-client-policy,cronexp:55 23 * * *,sync:"Sub-Store Sync",timeout:120,engine:auto -#!arguments-desc=\n1️⃣ ability\n\n默认已开启测落地能力\n需要配合脚本操作\n如 https://raw.githubusercontent.com/Keywos/rule/main/cname.js\n填写任意其他值关闭\n\n2️⃣ cronexp\n\n同步配置定时任务\n默认为每天 23 点 55 分\n\n定时任务指定时将订阅/文件上传到私有 Gist. 在前端, 叫做 '同步' 或 '同步配置'\n\n3️⃣ sync\n\n自定义定时任务名\n便于在脚本编辑器中选择\n若设为 # 可取消定时任务\n\n4️⃣ timeout\n\n超时, 单位为秒\n\n5️⃣ engine\n\n默认为自动使用 webview 引擎, 可设为指定 jsc, 但 jsc 容易爆内存 +#!arguments=ability:http-client-policy,cronexp:55 23 * * *,sync:"Sub-Store Sync",timeout:120,engine:auto,produce:"# Sub-Store Produce",produce_cronexp:50 */6 * * *,produce_sub:"sub1,sub2",produce_col:"col1,col2" +#!arguments-desc=\n1️⃣ ability\n\n默认已开启测落地能力\n需要配合脚本操作\n如 https://raw.githubusercontent.com/Keywos/rule/main/cname.js\n填写任意其他值关闭\n\n2️⃣ cronexp\n\n同步配置定时任务\n默认为每天 23 点 55 分\n\n定时任务指定时将订阅/文件上传到私有 Gist. 在前端, 叫做 '同步' 或 '同步配置'\n\n3️⃣ sync\n\n自定义定时任务名\n便于在脚本编辑器中选择\n若设为 # 可取消定时任务\n\n4️⃣ timeout\n\n超时, 单位为秒\n\n5️⃣ engine\n\n默认为自动使用 webview 引擎, 可设为指定 jsc, 但 jsc 容易爆内存\n\n6️⃣ produce\n\n自定义处理订阅的定时任务名\n一般用于定时处理耗时较长的订阅, 以更新缓存\n这样 Surge 中拉取的时候就能用到缓存, 不至于总是超时\n若设为 # 可取消此定时任务\n默认不开启\n\n7️⃣ produce_cronexp\n\n配置处理订阅的定时任务\n\n默认为每 6 小时\n\n9️⃣ produce_sub\n\n自定义需定时处理的单条订阅名\n多个用 , 连接\n\n🔟produce_col\n\n自定义需定时处理的组合订阅名\n多个用 , 连接 [MITM] hostname = %APPEND% sub.store @@ -12,4 +12,6 @@ Sub-Store Core=type=http-request,pattern=^https?:\/\/sub\.store\/((download)|api Sub-Store Simple=type=http-request,pattern=^https?:\/\/sub\.store,script-path=https://github.com/sub-store-org/Sub-Store/releases/latest/download/sub-store-0.min.js,requires-body=true,timeout={{{timeout}}},engine={{{engine}}} -{{{sync}}}=type=cron,cronexp="{{{cronexp}}}",wake-system=1,timeout={{{timeout}}},script-path=https://github.com/sub-store-org/Sub-Store/releases/latest/download/cron-sync-artifacts.min.js,engine={{{engine}}} \ No newline at end of file +{{{sync}}}=type=cron,cronexp="{{{cronexp}}}",wake-system=1,timeout={{{timeout}}},script-path=https://github.com/sub-store-org/Sub-Store/releases/latest/download/cron-sync-artifacts.min.js,engine={{{engine}}} + +{{{produce}}}=type=cron,cronexp="{{{produce_cronexp}}}",wake-system=1,timeout={{{timeout}}},script-path=https://github.com/sub-store-org/Sub-Store/releases/latest/download/cron-sync-artifacts.min.js,engine={{{engine}}},argument="sub={{{produce_sub}}}&col={{{produce_col}}}" \ No newline at end of file