From b1618c3803abf3ba7bce0f30c946d4cd8b8c2e0d Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 28 Feb 2025 14:07:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20`SUB=5FSTORE=5FPRODUCE?= =?UTF-8?q?=5FCRON`=20=E5=9C=A8=E5=90=8E=E5=8F=B0=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=AE=A2=E9=98=85,=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=B8=BA=20`0=20*/2=20*=20*=20*,sub,a;0=20*/3=20*=20*=20*,col,?= =?UTF-8?q?b`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/index.js | 35 ++++++++++++++++++++++++++++++++++- backend/src/restful/sync.js | 4 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) 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);