diff --git a/backend/package.json b/backend/package.json index b75086f..46bd833 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.59", + "version": "2.16.60", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/index.js b/backend/src/restful/index.js index f1dee5a..dbaee19 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -2,7 +2,7 @@ import express from '@/vendor/express'; import $ from '@/core/app'; import migrate from '@/utils/migration'; import download from '@/utils/download'; -import { syncArtifacts } from '@/restful/sync'; +import { syncArtifacts, produceArtifact } from '@/restful/sync'; import { gistBackupAction } from '@/restful/miscs'; import { TOKENS_KEY } from '@/constants'; @@ -75,6 +75,39 @@ export default function serve() { // 'Asia/Shanghai' // timeZone ); } + // 格式: 0 */2 * * *,sub,a;0 */3 * * *,col,b + // 每 2 小时处理一次单条订阅 a, 每 3 小时处理一次组合订阅 b + const produce_cron = eval('process.env.SUB_STORE_PRODUCE_CRON'); + if (produce_cron) { + $.info(`[PRODUCE CRON] ${produce_cron} enabled`); + const { CronJob } = eval(`require("cron")`); + produce_cron.split(/\s*;\s*/).map((item) => { + const [cron, type, name] = item.split(/\s*,\s*/); + new CronJob( + cron.trim(), + async function () { + try { + $.info( + `[PRODUCE CRON] ${type} ${name} ${cron} started`, + ); + await produceArtifact({ type, name }); + $.info( + `[PRODUCE CRON] ${type} ${name} ${cron} finished`, + ); + } catch (e) { + $.error( + `[PRODUCE CRON] ${type} ${name} ${cron} error: ${ + e.message ?? e + }`, + ); + } + }, // onTick + null, // onComplete + true, // start + // 'Asia/Shanghai' // timeZone + ); + }); + } const backend_download_cron = eval( 'process.env.SUB_STORE_BACKEND_DOWNLOAD_CRON', ); diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index 6117a72..f68c013 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -43,7 +43,7 @@ async function produceArtifact({ }) { platform = platform || 'JSON'; - if (type === 'subscription') { + if (['subscription', 'sub'].includes(type)) { let sub; if (name) { const allSubs = $.read(SUBS_KEY); @@ -190,7 +190,7 @@ async function produceArtifact({ } // produce return ProxyUtils.produce(proxies, platform, produceType, produceOpts); - } else if (type === 'collection') { + } else if (['collection', 'col'].includes(type)) { const allSubs = $.read(SUBS_KEY); const allCols = $.read(COLLECTIONS_KEY); const collection = findByName(allCols, name);