@@ -382,9 +382,12 @@ export class SynchronizeService {
382382 // 对比脚本列表和文件列表,进行同步
383383 const result : Promise < void > [ ] = [ ] ;
384384 const updateScript : Map < string , boolean > = new Map ( ) ;
385+ // 需要是同步操作,后续上传剩下的脚本
386+ // 最后使用 Promise.allSettled 进行等待
385387 uuidMap . forEach ( ( file , uuid ) => {
386388 const script = scriptMap . get ( uuid ) ;
387389 if ( script ) {
390+ scriptMap . delete ( uuid ) ;
388391 // 脚本存在但是文件不存在,则读取.meta.json内容判断是否需要删除脚本
389392 if ( ! file . script ) {
390393 result . push (
@@ -394,26 +397,23 @@ export class SynchronizeService {
394397 const metaJson = ( await meta . read ( "string" ) ) as string ;
395398 const metaObj = JSON . parse ( metaJson ) as SyncMeta ;
396399 if ( metaObj . isDeleted ) {
397- if ( script ) {
398- this . script . deleteScript ( script . uuid ) ;
399- InfoNotification (
400- i18n . t ( "notification.script_sync_delete" ) ,
401- i18n . t ( "notification.script_sync_delete_desc" , { scriptName : i18nName ( script ) } )
402- ) ;
403- }
404- scriptMap . delete ( uuid ) ;
400+ // 删除脚本
401+ this . script . deleteScript ( script . uuid , "sync" ) ;
402+ InfoNotification (
403+ i18n . t ( "notification.script_sync_delete" ) ,
404+ i18n . t ( "notification.script_sync_delete_desc" , { scriptName : i18nName ( script ) } )
405+ ) ;
405406 } else {
406- // 否则认为是一个无效的.meta文件, 进行删除
407+ // 否则认为是一个无效的.meta文件, 进行删除,并进行同步
407408 await fs . delete ( file . meta ! . name ) ;
409+ result . push ( this . pushScript ( fs , script ) ) ;
408410 }
409411 } ) ( )
410412 ) ;
411413 return ;
412414 }
413415 // 过滤掉无变动的文件
414416 if ( fileDigestMap [ file . script ! . name ] === file . script ! . digest ) {
415- // 删除了之后,剩下的就是需要上传的脚本了
416- scriptMap . delete ( uuid ) ;
417417 return ;
418418 }
419419 const updatetime = script . updatetime || script . createtime ;
@@ -427,10 +427,9 @@ export class SynchronizeService {
427427 updateScript . set ( uuid , true ) ;
428428 result . push ( this . pullScript ( fs , file as SyncFiles , cloudStatus [ uuid ] , script ) ) ;
429429 }
430- scriptMap . delete ( uuid ) ;
431430 return ;
432431 }
433- // 如果脚本不存在,且文件存在, 则安装脚本
432+ // 如果脚本不存在,但文件存在, 则安装脚本
434433 if ( file . script ) {
435434 if ( ! file . meta ) {
436435 // 如果.meta文件不存在,则删除脚本文件,并跳过
@@ -679,7 +678,10 @@ export class SynchronizeService {
679678 const config = await this . systemConfig . getCloudSync ( ) ;
680679 if ( config . enable ) {
681680 this . buildFileSystem ( config ) . then ( async ( fs ) => {
682- for ( const { uuid } of data ) {
681+ for ( const { uuid, deleteBy } of data ) {
682+ if ( deleteBy === "sync" ) {
683+ continue ;
684+ }
683685 await this . deleteCloudScript ( fs , uuid , config . syncDelete ) ;
684686 }
685687 } ) ;
0 commit comments