Skip to content

[v1.3] updateResource 相关代码调整#1193

Open
cyfung1031 wants to merge 28 commits intoscriptscat:release/v1.3from
cyfung1031:pr-updateResourceByType-return
Open

[v1.3] updateResource 相关代码调整#1193
cyfung1031 wants to merge 28 commits intoscriptscat:release/v1.3from
cyfung1031:pr-updateResourceByType-return

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Feb 3, 2026

概述 Descriptions

我都不知道要怎么说明了

反正就是有问题的部份改了

有些觉得奇怪的,我没有改,只加了 comment

  • 主要移除了 loadNow 那个设定。代码太难维护了。所有 fetch 资源都加一个 concurrency 控制,避免一次过爆发就好。要不要等就上层决定吧。
  • 现在 concurrency 控制 是五个 fetch 一组。这样就不会大量 fetch 冲到同一个 server (例如 GreasyFork )

变更内容 Changes

截图 Screenshots

@cyfung1031 cyfung1031 requested a review from CodFrm February 3, 2026 10:04
@cyfung1031 cyfung1031 marked this pull request as draft February 3, 2026 10:09
@cyfung1031
Copy link
Collaborator Author

cyfung1031 commented Feb 3, 2026

弹出安装页的部份要先下载好资源
而不是到按安裝才下载
所以先改成Draft PR

UI 部份另行处理
先处理好 JS代码的改动

Comment on lines 409 to 431
await this.scriptCodeDAO.save({
uuid: script.uuid,
code: param.code,
});
logger.info("install success");

// Cache更新 & 下载资源
await Promise.all([
compiledResourceUpdatePromise,
this.resourceService.updateResourceByType(script, "require"),
this.resourceService.updateResourceByType(script, "require-css"),
this.resourceService.updateResourceByType(script, "resource"),
this.resourceService.updateResourceByTypes(script, ["require", "require-css", "resource"]),
]);
// 如果资源不完整,还是要接受安装吗???

// 广播一下
// Runtime 會負責更新 CompiledResource
this.publishInstallScript(script, { update, upsertBy });

return { update };
})
.catch((e: any) => {
logger.error("install error", Logger.E(e));
throw e;
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodFrm scriptDAO 先 save 了显示成功。 如果资源下载失败,忽略掉是故意的吗?

是的话我就不改这做法
否则就改成下载不了不安装不更新

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

故意的,资源失败不影响脚本保存。不过这块逻辑可能还得优化一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我这个 PR 先不处理这个,先维持

Comment on lines 192 to 195
const updateTime = oldResources?.updatetime;
// 资源最后更新是24小时内则不更新
// 这里是假设 resources 都是 static. 使用者应该加 ?d=xxxx 之类的方式提示SC要更新资源
if (updateTime && updateTime > Date.now() - 86400_000) return;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodFrm 原代码有这个 updateTime 检查操作。但脚本更新可以是每6小时做一次。如果脚本更新了但资源不更新,好像有点奇怪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前考虑过不做这个检查,感觉也可以,资源加载下来就不再失效,除非修改url

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我先不改动。你有需要再改一下吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants