@@ -54,6 +54,19 @@ export type TCheckScriptUpdateOption = Partial<
5454
5555export type TOpenBatchUpdatePageOption = { q : string ; dontCheckNow : boolean } ;
5656
57+ export type TScriptInstallParam = {
58+ script : Script ; // 脚本信息(包含脚本的基础元数据)
59+ code : string ; // 脚本源码内容
60+ upsertBy ?: InstallSource ; // 安装/更新来源(用于标识脚本来源渠道)
61+ createtime ?: number ; // 导入时指定的创建时间(时间戳,毫秒)
62+ updatetime ?: number ; // 导入时指定的最后更新时间(时间戳,毫秒)
63+ } ;
64+
65+ export type TScriptInstallReturn = {
66+ update : boolean ; // 是否为更新操作(true 表示更新,false 表示新增)
67+ updatetime : number | undefined ; // 实际生效的更新时间(时间戳,毫秒)
68+ } ;
69+
5770export class ScriptService {
5871 logger : Logger ;
5972 scriptCodeDAO : ScriptCodeDAO = new ScriptCodeDAO ( ) ;
@@ -369,14 +382,8 @@ export class ScriptService {
369382 return this . mq . publish < TInstallScript > ( "installScript" , { script, ...options } ) ;
370383 }
371384
372- // 安装脚本 / 更新腳本
373- async installScript ( param : {
374- script : Script ;
375- code : string ;
376- upsertBy ?: InstallSource ;
377- createtime ?: number ;
378- updatetime ?: number ;
379- } ) {
385+ // 安装脚本 / 更新脚本
386+ async installScript ( param : TScriptInstallParam ) : Promise < TScriptInstallReturn > {
380387 param . upsertBy = param . upsertBy || "user" ;
381388 const { script, upsertBy, createtime, updatetime } = param ;
382389 // 删 storage cache
@@ -427,10 +434,11 @@ export class ScriptService {
427434 ] ) ;
428435
429436 // 广播一下
430- // Runtime 會負責更新 CompiledResource
437+ // Runtime 会负责更新 CompiledResource
431438 this . publishInstallScript ( script , { update, upsertBy } ) ;
432439
433- return { update } ;
440+ // 传回(由后台控制的)实际更新时间,让 editor 中的script能保持正确的更新时间
441+ return { update, updatetime : script . updatetime } ;
434442 } )
435443 . catch ( ( e : any ) => {
436444 logger . error ( "install error" , Logger . E ( e ) ) ;
@@ -1144,7 +1152,7 @@ export class ScriptService {
11441152 }
11451153
11461154 isInstalled ( { name, namespace } : { name : string ; namespace : string } ) : Promise < App . IsInstalledResponse > {
1147- // 用於 window.external
1155+ // 用于 window.external
11481156 return this . scriptDAO . findByNameAndNamespace ( name , namespace ) . then ( ( script ) => {
11491157 if ( script ) {
11501158 return {
0 commit comments