MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / installScript

Method installScript

src/app/service/service_worker/script.ts:418–503  ·  view source on GitHub ↗
(param: TScriptInstallParam)

Source from the content-addressed store, hash-verified

416
417 // 安装脚本 / 更新脚本
418 async installScript(param: TScriptInstallParam): Promise<TScriptInstallReturn> {
419 param.upsertBy = param.upsertBy || "user";
420 const { script, upsertBy, createtime, updatetime } = param;
421 // 删 storage cache
422 const compiledResourceUpdatePromise = this.compiledResourceDAO.delete(script.uuid);
423 const logger = this.logger.with({
424 name: script.name,
425 uuid: script.uuid,
426 version: script.metadata.version?.[0] || "0.0",
427 upsertBy,
428 });
429 let update = false;
430 // 判断是否已经安装
431 const oldScript = await this.scriptDAO.get(script.uuid);
432 if (oldScript) {
433 // 执行更新逻辑
434 update = true;
435 script.selfMetadata = oldScript.selfMetadata;
436 // 如果已安装的脚本是由 Subscribe 安装,即使是手动更新也不会影响跟 Subscribe 关联
437 if (oldScript.subscribeUrl && oldScript.origin) {
438 // origin 和 subscribeUrl 保持不变
439 // @downloadURL @updateURL 随脚本最新代码而更新
440 script.origin = oldScript.origin;
441 script.subscribeUrl = oldScript.subscribeUrl;
442 }
443 }
444 if (script.ignoreVersion) script.ignoreVersion = "";
445 if (createtime) {
446 script.createtime = createtime;
447 }
448 if (updatetime) {
449 script.updatetime = updatetime;
450 }
451 // 拖拉安装等同本地创建脚本
452 if (script.origin?.startsWith("file:///*from-local*/")) {
453 script.origin = "";
454 script.originDomain = "";
455 script.downloadUrl = "";
456 script.checkUpdateUrl = "";
457 }
458 // 现存的脚本:以最初的安装(即 createtime)为标准,回填 origin 用于更新检查。
459 // 如果最初是从网络安装,之后拖拉安装本机档案,则保留 origin 资讯。
460 // 如果本机安装的版本号较低,则会在下次更新检查时提醒有更新。那个时候,用户可以选择更新至网络上最新版本,或忽略并保留本机版本。
461 // 跳过 ScriptCat 旧版本 (1.0.0-beta.2 ~ 1.4.x,自 commit d9b0eeede1a8b114f79a43fade99d825323c63f6 @ 2025.07.23)
462 // 误写入的 file:///*from-local*/ 与 file://-/ 前缀
463 if (
464 oldScript &&
465 script.createtime === oldScript.createtime &&
466 oldScript.origin &&
467 !script.origin &&
468 !oldScript.origin.startsWith("file:///*from-local*/") &&
469 !oldScript.origin.startsWith("file://-/")
470 ) {
471 script.origin = oldScript.origin;
472 script.originDomain = oldScript.originDomain;
473 script.downloadUrl = oldScript.downloadUrl;
474 script.checkUpdateUrl = oldScript.checkUpdateUrl;
475 }

Callers 5

installByUrlMethod · 0.95
installByCodeMethod · 0.95
_checkScriptUpdateMethod · 0.95
pullScriptMethod · 0.80

Calls 9

publishInstallScriptMethod · 0.95
withMethod · 0.80
updateResourceByTypesMethod · 0.80
errorMethod · 0.80
EMethod · 0.80
deleteMethod · 0.65
getMethod · 0.65
saveMethod · 0.65
infoMethod · 0.45

Tested by

no test coverage detected