@@ -20,6 +20,10 @@ import {
2020} from '@/restful/errors' ;
2121import Gist from '@/utils/gist' ;
2222import { archiveArtifact } from '@/utils/archive' ;
23+ import {
24+ normalizeArtifactCron ,
25+ refreshArtifactCronJobs ,
26+ } from '@/utils/artifact-cron' ;
2327
2428const ARTIFACT_GIST_PLACEHOLDER_FILENAME = '.sub-store-placeholder' ;
2529const ARTIFACT_GIST_PLACEHOLDER_CONTENT = [
@@ -109,6 +113,7 @@ async function restoreArtifacts(_, res) {
109113 }
110114 } ) ;
111115 $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
116+ refreshArtifactCronJobs ( ) ;
112117 } catch ( err ) {
113118 $ . error ( `查找 Sub-Store Gist 时发生错误: ${ err . message ?? err } ` ) ;
114119 throw err ;
@@ -133,9 +138,15 @@ function getAllArtifacts(req, res) {
133138}
134139
135140function replaceArtifact ( req , res ) {
136- const allArtifacts = req . body ;
137- $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
138- success ( res ) ;
141+ try {
142+ const allArtifacts = req . body ;
143+ allArtifacts . forEach ( normalizeArtifactCron ) ;
144+ $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
145+ refreshArtifactCronJobs ( ) ;
146+ success ( res ) ;
147+ } catch ( error ) {
148+ failed ( res , error ) ;
149+ }
139150}
140151
141152async function getArtifact ( req , res ) {
@@ -188,8 +199,15 @@ function updateArtifact(req, res) {
188199 ) ;
189200 return ;
190201 }
202+ try {
203+ normalizeArtifactCron ( newArtifact ) ;
204+ } catch ( error ) {
205+ failed ( res , error ) ;
206+ return ;
207+ }
191208 updateByName ( allArtifacts , oldName , newArtifact ) ;
192209 $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
210+ refreshArtifactCronJobs ( ) ;
193211 success ( res , newArtifact ) ;
194212 } else {
195213 failed (
@@ -244,6 +262,7 @@ function createArtifactItem(artifact) {
244262 }
245263
246264 $ . info ( `正在创建远程配置:${ artifact . name } ` ) ;
265+ normalizeArtifactCron ( artifact ) ;
247266 const allArtifacts = $ . read ( ARTIFACTS_KEY ) ;
248267 if ( findByName ( allArtifacts , artifact . name ) ) {
249268 throw new RequestInvalidError (
@@ -253,6 +272,7 @@ function createArtifactItem(artifact) {
253272 }
254273 insertByPosition ( allArtifacts , artifact , getCreateItemPosition ( ) ) ;
255274 $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
275+ refreshArtifactCronJobs ( ) ;
256276 return artifact ;
257277}
258278
@@ -299,6 +319,7 @@ async function deleteArtifactItem(name) {
299319 }
300320 deleteByName ( allArtifacts , name ) ;
301321 $ . write ( allArtifacts , ARTIFACTS_KEY ) ;
322+ refreshArtifactCronJobs ( ) ;
302323 return {
303324 artifact,
304325 remote,
0 commit comments