Conversation
你看一看 1. 大文件读取内存占用过高(最可能卡住 openspec 测试的地方)问题: 解决方案:
额外建议:如果上层 FileSystem 接口允许,考虑让 2. write 方法对 content 类型支持不完整 & 未做类型防护问题: 解决方案:
3. forcePathStyle 硬编码为 true,导致 AWS 官方区域可能用不了 virtual-hosted style问题: 解决方案:
4. Metadata 键名和格式不规范问题:
解决方案: 5. openDir 方法中重复创建 client(浪费资源 & 凭证冗余)问题: 解决方案: 总结优先级修复顺序建议
这些改动后,S3 支持应该能稳定很多。如果后续作者有更具体的报错日志或测试案例,可以再针对性调整。 |
|
參考一下吧 这些问题大多是“隐形坑”,在小文件/本地测试时不明显,但真实同步场景(大文件、多目录、各种 S3 兼容服务)很容易暴露。 6. endpoint 配置不完整(缺少协议,SDK 容易报 InvalidEndpoint)问题: 解决方案:
7. list() 方法分页无上限 + 内存累积(大目录风险)问题:
解决方案:
8. verify() 方法的错误映射不完整(漏掉常见权限/网络错误)问题: 解决方案: 9. openDir() 中重复构造对象但凭证传空字符串(逻辑冗余)问题: 解决方案: 当前整体评估
建议作者:
|
|
PutObjectCommand 的 Body 可以直接写入 Blob content 为什么直接传 Blob 更好?
(alias) type StreamingBlobPayloadInputTypes = string | Blob | Uint8Array | Buffer | Stream.Readable | Uint8Array | ReadableStream FAQ: Why does the type union mix mutually exclusive runtime types, namely Node.js and browser types? There are several reasons: For backwards compatibility. As a convenient compromise solution so that users in either environment may use the types without customization. The SDK does not have static type information about the exact implementation of the HTTP RequestHandler being used in your client(s) (e.g. fetch, XHR, node:http, or node:http2), given that it is chosen at runtime. There are multiple possible request handlers in both the Node.js and browser runtime environments. Rather than restricting the type to a known common format (Uint8Array, for example) which doesn't include a universal streaming format in the currently supported Node.js versions, the type declaration is widened to multiple possible formats. It is up to the user to ultimately select a compatible format with the runtime and HTTP handler implementation they are using. Usage: The typical solution we expect users to have is to manually narrow the type when needed, picking the appropriate one out of the union according to the runtime environment and specific request handler. There is also the type utility "NodeJsClient", "BrowserClient" and more exported from this package. These can be applied at the client level to pre-narrow these streaming payload blobs. For usage see the readme.md in the root of the @smithy/types NPM package. |
|
openspec 是一个新的vibe coding方法论,你的AI理解似乎有点问题; 我只是拿这个需求来试试,还没完成,我提交上来先占个位,不过感觉你好像快弄完了。👀 |
哈哈。。AI嘛 |
There was a problem hiding this comment.
Pull request overview
该 PR 为 ScriptCat 的云端同步/备份文件系统新增 **Amazon S3(含 S3 兼容服务)**选项,并在 MV3 Service Worker 环境下通过原生 fetch + SigV4 实现轻量 S3 客户端以绕开 SDK 依赖问题。
Changes:
- 在设置页文件系统类型中新增
s3选项,并补充对应参数表单字段 - 增加 S3 文件系统实现(list/open/create/delete/getDirUrl)及底层 SigV4 签名 HTTP 客户端
- 为多语言翻译新增 S3 相关字段文案;更新 lockfile
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/components/FileSystemParams/index.tsx | 文件系统下拉列表新增 Amazon S3 入口 |
| src/locales/zh-TW/translation.json | 新增 S3 参数字段翻译 |
| src/locales/zh-CN/translation.json | 新增 S3 参数字段翻译 |
| src/locales/vi-VN/translation.json | 新增 S3 参数字段翻译 |
| src/locales/ru-RU/translation.json | 新增 S3 参数字段翻译 |
| src/locales/ja-JP/translation.json | 新增 S3 参数字段翻译 |
| src/locales/en-US/translation.json | 新增 S3 参数字段翻译 |
| src/locales/de-DE/translation.json | 新增 S3 参数字段翻译 |
| src/locales/ach-UG/translation.json | 新增 S3 参数字段翻译 |
| pnpm-lock.yaml | lockfile 更新(新增 libc 字段等) |
| packages/filesystem/s3/s3.ts | S3FileSystem 实现(含 ListObjectsV2 XML 解析与分页) |
| packages/filesystem/s3/rw.ts | S3 文件读写器(GET/PUT) |
| packages/filesystem/s3/client.ts | 轻量 S3 HTTP 客户端(SigV4 签名 + fetch) |
| packages/filesystem/factory.ts | FileSystemFactory 增加 s3 类型与参数定义 |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
| } | ||
|
|
||
| continuationToken = result.nextContinuationToken; | ||
| } while (continuationToken); |
There was a problem hiding this comment.
list() 的分页循环条件仅依赖 nextContinuationToken(do...while(continuationToken)),而 parseListObjectsV2 同时返回了 isTruncated。若解析失败导致 token 丢失但响应仍标记 IsTruncated=true,会静默提前结束导致丢文件。建议循环条件以 isTruncated 为准,并在 isTruncated=true 但 token 缺失时显式报错/告警。
| async function sha256(data: string | Uint8Array): Promise<ArrayBuffer> { | ||
| const encoded = typeof data === "string" ? new TextEncoder().encode(data) : data; | ||
| return crypto.subtle.digest("SHA-256", encoded.buffer as ArrayBuffer); | ||
| } |
There was a problem hiding this comment.
sha256() 对 Uint8Array 入参使用 encoded.buffer 进行 digest,这在 Uint8Array 是子视图(byteOffset/byteLength 非整段 buffer)时会把多余字节也算入哈希,导致签名/校验错误。建议传入一个与视图范围一致的 ArrayBuffer(例如 slice(byteOffset, byteOffset+byteLength))或直接对 Uint8Array 视图做 digest。
There was a problem hiding this comment.
typescript 害人不浅
一直在搞什么ArrayBufferLike ArrayBufferView SharedArrayBuffer 的
| body: options?.body | ||
| ? options.body instanceof Uint8Array | ||
| ? (options.body.buffer as ArrayBuffer) | ||
| : options.body | ||
| : undefined, |
There was a problem hiding this comment.
request() 在 options.body 为 Uint8Array 时将其转换为 options.body.buffer 传给 fetch。若该 Uint8Array 不是从 0 开始的整段视图,会把 buffer 的其他字节也一并发送,且与前面用于计算 payloadHash 的内容不一致,可能导致上传数据损坏或签名不匹配。建议直接把 Uint8Array 传给 fetch,或按 byteOffset/byteLength slice 出精确的 ArrayBuffer。
| function parseListObjectsV2(xml: string): ListObjectsV2Result { | ||
| const contents: ListObjectsV2Result["contents"] = []; | ||
| const contentsRegex = /<Contents>([\s\S]*?)<\/Contents>/g; | ||
| let match; | ||
| while ((match = contentsRegex.exec(xml)) !== null) { | ||
| const block = match[1]; | ||
| const key = block.match(/<Key>([\s\S]*?)<\/Key>/)?.[1] || ""; | ||
| const lastModified = block.match(/<LastModified>([\s\S]*?)<\/LastModified>/)?.[1] || ""; | ||
| const etag = block.match(/<ETag>([\s\S]*?)<\/ETag>/)?.[1] || ""; | ||
| const size = parseInt(block.match(/<Size>([\s\S]*?)<\/Size>/)?.[1] || "0", 10); | ||
| contents.push({ key, lastModified, etag, size }); |
There was a problem hiding this comment.
parseListObjectsV2 目前用正则直接截取 / 等字段,但 S3 的 XML 会对特殊字符进行实体转义(如 &、")。不做实体反转义会导致包含特殊字符的对象 key 被解析错误,进而影响 open/delete/list 的一致性。建议至少对捕获的文本做 XML entity decode,或引入更稳健的轻量 XML 解析方式。
There was a problem hiding this comment.
概述 Descriptions
尝试了下 openspec,还是有些问题,先存一下,后续再继续处理
close #1146
使用sdk有不少问题,由于是运行在SW环境,没有DOMParse,让AI实现了一个简单的client
变更内容 Changes
截图 Screenshots