Repository navigation
Cbox 文件改名/移动·后端:PATCH /files/:id 扩展 name / folderId - #34
Merged
todosdev[bot] merged 2 commits intoNov 19, 2026
Merged
Conversation
Support renaming and moving files via PATCH /api/files/:id with validation, conflict checks, and preservation of R2 keys and shares. Checkpoint: jeIm07FRyt8ipQ-pMLlfK
Empty string or whitespace folderId in PATCH /files/:id is now treated as null (root directory), consistent with upload route. Checkpoint: toimCK-PW4mTk6Sv-G6eu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PATCH /api/files/:id接口支持可选的name(改名)与folderId(移动,null或空白字符串表示移至根目录),支持与现有expiresIn任意组合提交。isValidFolderName校验文件名合法性、findFolderById校验目标文件夹归属,并使用checkFileNameConflict执行目标目录重名冲突检测(排除自身)。r2_key)与存储内容不变,已有分享链接继续生效且下载文件名自动对齐新名称。Changes
worker/src/db/queries/files.ts):checkFileNameConflict支持可选参数excludeFileId,在目标目录同名检查时排除文件自身当前记录,防止同名未变更时误报冲突。updateFileRecord函数,支持动态更新name、folder_id与expires_at;在缩短有效期时同步截断超期分享。重构updateFileExpiration复用该方法。worker/src/routes/files.ts):PATCH /api/files/:id请求体验证,确保name、folderId、expiresIn至少提供一项,否则返回400 INVALID_REQUEST。isValidFolderName校验,非法返回400 INVALID_FILENAME。null或空串/纯空白解析为根目录;指定文件夹经findFolderById验证归属,不存在或越权返回404 FOLDER_NOT_FOUND。409 FILE_NAME_CONFLICT;更新成功返回最新的FileView。worker/test/files-upload-download.test.ts):Testing
pnpm lint、pnpm format:check、pnpm typecheck全部通过(0 错误 0 警告)。pnpm test全部通过(worker 36 文件 260 项测试全绿,web 22 文件 174 项测试全绿)。2457d687)全项通过。