@@ -66,14 +66,18 @@ type ScriptcatSyncStatus = {
6666 updatetime : number ; // 更新时间
6767} ;
6868
69- type PushScriptParam = TInstallScriptParams ;
69+ type PushScriptParam = TInstallScriptParams & Partial < Pick < Script , "createtime" | "updatetime" > > ;
7070
7171type FileDigestMap = {
7272 [ key : string ] : string ;
7373} ;
7474
7575const SYNC_SERVICE_TASK_KEY = "cloud_sync_queue" ;
7676
77+ function getScriptModifiedDate ( script : PushScriptParam ) : number {
78+ return script . updatetime || script . createtime || Date . now ( ) ;
79+ }
80+
7781export class SynchronizeService {
7882 logger : Logger ;
7983
@@ -423,7 +427,9 @@ export class SynchronizeService {
423427 await this . script . deleteScript ( script . uuid , "sync" ) ;
424428 InfoNotification (
425429 i18n . t ( "notification.script_sync_delete" ) ,
426- i18n . t ( "notification.script_sync_delete_desc" , { scriptName : i18nName ( script ) } )
430+ i18n . t ( "notification.script_sync_delete_desc" , {
431+ scriptName : i18nName ( script ) ,
432+ } )
427433 ) ;
428434 } else {
429435 // 否则认为是一个无效的.meta文件,进行删除,并进行同步
@@ -535,7 +541,8 @@ export class SynchronizeService {
535541 }
536542 } ) ;
537543 // 保存脚本猫同步状态
538- const syncFile = await fs . create ( "scriptcat-sync.json" ) ;
544+ const modifiedDate = Date . now ( ) ;
545+ const syncFile = await fs . create ( "scriptcat-sync.json" , { modifiedDate } ) ;
539546 await syncFile . write ( JSON . stringify ( scriptcatSync , null , 2 ) ) ;
540547 this . logger . info ( "sync scriptcat-sync.json file success" ) ;
541548 }
@@ -575,7 +582,8 @@ export class SynchronizeService {
575582 await fs . delete ( filename ) ;
576583 if ( syncDelete ) {
577584 // 留下一个.meta.json删除标记
578- const meta = await fs . create ( `${ uuid } .meta.json` ) ;
585+ const modifiedDate = Date . now ( ) ;
586+ const meta = await fs . create ( `${ uuid } .meta.json` , { modifiedDate } ) ;
579587 await meta . write (
580588 JSON . stringify ( < SyncMeta > {
581589 uuid : uuid ,
@@ -606,12 +614,13 @@ export class SynchronizeService {
606614 file : filename ,
607615 } ) ;
608616 try {
609- const w = await fs . create ( filename ) ;
617+ const modifiedDate = getScriptModifiedDate ( script ) ;
618+ const w = await fs . create ( filename , { modifiedDate } ) ;
610619 // 获取脚本代码
611620 const code = await this . scriptCodeDAO . get ( script . uuid ) ;
612621 const scriptCode = code ! . code ;
613622 await w . write ( scriptCode ) ;
614- const meta = await fs . create ( metaFilename ) ;
623+ const meta = await fs . create ( metaFilename , { modifiedDate } ) ;
615624 const metaJson = JSON . stringify ( < SyncMeta > {
616625 uuid : script . uuid ,
617626 origin : script . origin ,
0 commit comments