Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Nov 14, 2025

概述 Descriptions

依存: #949

变更内容 Changes

截图 Screenshots

@CodFrm CodFrm requested a review from Copilot November 14, 2025 09:49
Copilot finished reviewing on behalf of CodFrm November 14, 2025 09:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

这个 PR 修复了脚本备份导出和导入功能中不保留脚本最后修改时间的问题(issue #936)。主要通过创建 JSZip 时区处理工具类,在备份数据中添加 lastModificationDate 字段,并在导入/导出时正确设置文件修改时间。

  • 新增 jszip-x.ts 工具类处理 JSZip 的 UTC 时区问题
  • 在备份数据结构中添加 lastModificationDate 字段
  • 更新文件系统接口以支持 FileCreateOptions 参数传递修改时间
  • 修改脚本安装接口以支持指定创建和更新时间

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/pkg/utils/jszip-x.ts 新增 JSZip 包装工具类,处理时区偏移问题,提供 createJSZip 和 loadAsyncJSZip 方法
src/pkg/backup/struct.ts 在 ScriptBackupData 和 SubscribeBackupData 中添加可选的 lastModificationDate 字段
src/pkg/backup/import.ts 解析备份文件时从文件元数据中读取 updatetime 并设置为 lastModificationDate
src/pkg/backup/export.ts 导出时根据 lastModificationDate 设置文件的修改时间
src/pkg/backup/utils.ts 更新类型引用从 JSZip 改为 JSZipFile
src/pkg/backup/backup.test.ts 更新测试用例以验证 lastModificationDate 字段
src/pages/import/App.tsx 导入时传递 createtime 和 updatetime 到 scriptClient.install
src/pages/install/App.tsx 更新 scriptClient.install 调用参数结构
src/pages/options/routes/script/ScriptEditor.tsx 更新 scriptClient.install 调用参数结构
src/pages/components/CloudScriptPlan/index.tsx 使用 createJSZip 替代 new JSZip()
src/app/service/service_worker/script.ts installScript 方法添加 createtime 和 updatetime 可选参数
src/app/service/service_worker/synchronize.ts 导出备份时计算并设置 lastModificationDate,使用 createJSZip
src/app/service/service_worker/value.ts 重构 getScriptValue 方法以返回详细信息
src/app/service/service_worker/resource.ts importResource 方法中使用资源的时间戳(存在逻辑错误)
src/app/service/service_worker/client.ts 更新 ScriptClient.install 方法签名
packages/filesystem/filesystem.ts 添加 FileCreateOptions 类型定义
packages/filesystem/zip/*.ts 实现文件修改时间的读写,处理时区转换
packages/filesystem/webdav/*.ts 添加 FileCreateOptions 参数支持(未实现)
packages/filesystem/onedrive/*.ts 添加 FileCreateOptions 参数支持(未实现)
packages/filesystem/googledrive/*.ts 添加 FileCreateOptions 参数支持(未实现)
packages/filesystem/dropbox/*.ts 添加 FileCreateOptions 参数支持(未实现)
packages/filesystem/baidu/*.ts 添加 FileCreateOptions 参数支持(未实现)
packages/cloudscript/local.ts 更新类型引用从 JSZip 改为 JSZipFile
scripts/pack.js 使用 createJSZip 替代 new JSZip()

Comment on lines 317 to 318
createtime: ts || Math.min(ts, now),
updatetime: ts || Math.min(ts, now),
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

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

逻辑错误:当 ts 为 0 时,ts || Math.min(ts, now) 会因为 ts 为假值而计算 Math.min(0, now),结果为 0。但当 ts 有值时,会直接返回 ts 而不会执行 Math.min

正确的逻辑应该是:

createtime: ts || now,
updatetime: ts || now,

或者如果需要确保不使用未来时间:

createtime: Math.min(ts || now, now),
updatetime: Math.min(ts || now, now),
Suggested change
createtime: ts || Math.min(ts, now),
updatetime: ts || Math.min(ts, now),
createtime: ts || now,
updatetime: ts || now,

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

呀。对。反过来了。要改一下

Copy link
Collaborator Author

@cyfung1031 cyfung1031 Nov 14, 2025

Choose a reason for hiding this comment

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

resolved in af4f346

}

async create(path: string): Promise<FileWriter> {
async create(path: string, _opts?: FileCreateOptions): Promise<FileWriter> {
Copy link
Member

Choose a reason for hiding this comment

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

不用的话,最后一个参数可以不填写

Suggested change
async create(path: string, _opts?: FileCreateOptions): Promise<FileWriter> {
async create(path: string): Promise<FileWriter> {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

接口有两个参数
表示清晰

install(script: Script, code: string, upsertBy: InstallSource = "user"): Promise<{ update: boolean }> {
return this.doThrow("install", { script, code, upsertBy });
install(params: {
details: Script;
Copy link
Member

Choose a reason for hiding this comment

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

不用 script 了吗?后续也是 detailsscript 变来变去的

Suggested change
details: Script;
script: Script;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

日后可能会把 subscribe 和 script 都用同一个变数名
用哪个都没所谓

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我还是先改回 script. 日后有机会再处理名字

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 CodFrm merged commit d061699 into scriptscat:develop/raw-message Nov 15, 2025
3 checks passed
@CodFrm CodFrm mentioned this pull request Nov 15, 2025
CodFrm pushed a commit that referenced this pull request Nov 15, 2025
* 修正汇出汇入不依照脚本最后修改日期时间问题

* 修正 ValueStorage ts 问题

* 調整 setValues

* 小修正

* 修正

* details -> script

* 名字统一为 zipFile

(cherry picked from commit d061699)
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