Repository navigation
fix(fs): return FOLDER type for directories in fs/get responses - #3114
Merged
Merged
Conversation
- FsGet, SharingGet and the MCP fs.get tool computed the response 'type' field with utils.GetFileType, which only looks at the file name extension, so a directory could never be reported as FOLDER (e.g. a directory named 'movie.mp4' was returned as VIDEO) - Use utils.GetObjType(name, isDir) instead, matching fs/list, search, archive and sharing-list responses - GetObjType falls back to GetFileType for non-directories, so file responses are unchanged
jyxjjj
approved these changes
Sep 23, 2026
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 / 摘要
/api/fs/get(以及分享页的 SharingGet、MCP 的openlist.fs.get)在计算响应type字段时使用utils.GetFileType,只看文件扩展名,因此目录在 fs/get 里永远拿不到 FOLDER(1):名为movie.mp4的目录返回type: 2 (VIDEO),普通目录返回type: 0 (UNKNOWN)。而/api/fs/list、search、archive、sharing-list 均使用utils.GetObjType(name, isDir),目录恒为 FOLDER——同一对象在两个核心 API 中类型语义不一致。本 PR 将这 3 处改为
utils.GetObjType(obj.GetName(), obj.IsDir()),与其余端点对齐。GetObjType在非目录时完全等价于GetFileType,文件响应零变化,只有目录的type统一为 FOLDER。说明:官方前端无用户可见影响(前端一律用
is_dir分流目录/文件,图标与菜单使用的数据均来自 fs/list);本 PR 定位是 API 一致性修复,主要价值是避免第三方客户端用type == FOLDER判断目录时,在 fs/get 上出现一致性的判断错误(响应用于判断目录的is_dir字段始终存在)。实测复现(main 分支本地运行,Local driver):
movie.mp4/(目录)plain_dir/(目录)test.mp4(视频文件)(
/api/fs/get与分享页 get、MCP fs.get 响应中,目录的type字段由按扩展名推断(可能为 VIDEO/AUDIO/IMAGE/TEXT/UNKNOWN)修正为恒为 FOLDER(1);文件响应不变。)Testing / 测试
go test ./...已运行
go build ./server/...、go vet ./server/handles/ ./server/mcp/、go test ./server/handles/ ./server/mcp/(全部通过)。全量go test ./...在本机有两项与本改动无关的既有失败:internal/offline_download/{115,115_open,pikpak}构建失败(上游 commit ace7482 引入的non-constant format stringvet 错误)、pkg/aria2/rpc需要本机运行 aria2 守护进程。Manual test / 手动测试:
main 分支本地运行 + Local driver 复现目录 type 不一致(见上表);修改后重新构建:目录
fs/get返回type: 1 (FOLDER),视频文件仍为type: 2 (VIDEO),与 fs/list 一致。Checklist / 检查清单
gofmt,go fmt, orprettierwhere applicable. / 我已按适用情况使用gofmt、go fmt或prettier格式化变更代码。AI Disclosure / AI 使用声明
Tools used / 使用工具:
Usage scope / 使用范围:
Code generation / 代码生成
Refactoring / 重构
Documentation / 文档
Tests / 测试
Translation / 翻译
Review assistance / 审查辅助
I have reviewed and validated all AI-assisted content included in this PR. / 我已审核并验证此 PR 中的所有 AI 辅助内容。
I have ensured that all AI-assisted commits include
Co-Authored-Byattribution. / 我已确保所有 AI 辅助提交都包含Co-Authored-By归属信息。(按仓库 AGENTS.md 的规则:所使用的助手不在列出名单内,因此 commit 中未添加
Co-Authored-Bytrailer。)