Skip to content

fix(fs): return FOLDER type for directories in fs/get responses - #3114

Merged
jyxjjj merged 1 commit into
OpenListTeam:mainfrom
ZRHann:fix/dir-obj-type
Sep 23, 2026
Merged

jyxjjj merged 1 commit into
OpenListTeam:mainfrom
ZRHann:fix/dir-obj-type

Conversation

@ZRHann

@ZRHann ZRHann commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

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):

对象 fs/get 的 type(修复前) fs/list 的 type
movie.mp4/(目录) 2 (VIDEO) 1 (FOLDER)
plain_dir/(目录) 0 (UNKNOWN) 1 (FOLDER)
test.mp4(视频文件) 2 (VIDEO) 2 (VIDEO)
  • This PR has breaking changes. / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior. / 此 PR 修改了公开 API、配置、存储格式或迁移行为。

(/api/fs/get 与分享页 get、MCP fs.get 响应中,目录的 type 字段由按扩展名推断(可能为 VIDEO/AUDIO/IMAGE/TEXT/UNKNOWN)修正为恒为 FOLDER(1);文件响应不变。)

  • This PR requires corresponding changes in related repositories. / 此 PR 需要关联仓库同步修改。

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 string vet 错误)、pkg/aria2/rpc 需要本机运行 aria2 守护进程。

  • Manual test / 手动测试:

    main 分支本地运行 + Local driver 复现目录 type 不一致(见上表);修改后重新构建:目录 fs/get 返回 type: 1 (FOLDER),视频文件仍为 type: 2 (VIDEO),与 fs/list 一致。

Checklist / 检查清单

  • I have read CONTRIBUTING. / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct. / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable. / 我已按适用情况使用 gofmt、go fmt 或 prettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable. / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content. / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明): Kimi Code

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-By attribution. / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

(按仓库 AGENTS.md 的规则:所使用的助手不在列出名单内,因此 commit 中未添加 Co-Authored-By trailer。)

  • I can reproduce all AI-assisted content included in this PR without any AI tools. / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

- 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
jyxjjj merged commit 6c60091 into OpenListTeam:main Sep 23, 2026
9 checks passed
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