Skip to content

feat(task): show offline download file info - #547

Open
gengjiawen wants to merge 2 commits into
OpenListTeam:mainfrom
gengjiawen:feat/offline-download-task-file-info
Open

feat(task): show offline download file info#547
gengjiawen wants to merge 2 commits into
OpenListTeam:mainfrom
gengjiawen:feat/offline-download-task-file-info

Conversation

@gengjiawen

Copy link
Copy Markdown

Summary / 摘要

  • Show file name and file size in the expanded view of running offline download tasks.

  • Add optional file_name and file_size fields to the frontend task response type.

  • Add task attribute labels for the new offline download file info rows.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。

  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。

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

Related repository PRs / 关联仓库 PR:

Testing / 测试

  • go test ./...
  • pnpm exec prettier --write src/types/task.ts src/pages/manage/tasks/Task.tsx src/lang/en/tasks.json
  • pnpm lint: currently blocked by existing TypeScript errors in src/pages/home/previews/archive.tsx and src/pages/manage/storages/AddOrEdit.tsx.
  • Manual test / 手动测试: not run locally; depends on the related backend API fields.

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.
    / 我已按适用情况使用 gofmtgo fmtprettier 格式化变更代码。
  • 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) / 其他(请注明):

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 归属信息。

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

Co-authored-by: Codex <codex@openai.com>

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

结论:实现没问题,有两点建议讨论

在离线下载任务的展开视图中显示文件名和大小,是很实用的改进——任务名往往是一长串 URL,光看它判断不出实际下到了什么。file_name / file_size 都设为可选字段,后端未返回时不会渲染,向后兼容处理得当;fileSize()props.file_size || props.total_bytes 兜底也合理,后端没给显式大小时仍能显示已知总量。

一、限定 done === "undone" 是否合适

const showFileInfo = () =>
  props.type === "offline_download" && props.done === "undone"

这样只有进行中的任务会显示文件信息,已完成和已失败的任务不显示。我理解意图可能是「完成后去文件列表看即可」,但从排查角度看,恰恰是已结束的任务更需要这个信息:任务失败时想知道它当时识别到的文件名和大小(比如是不是超出了预期体积),已完成时想确认下到的到底是哪个文件。这两类任务停留在列表里的时间也更长。

如果没有特别理由,建议去掉 done 的限制,只保留 props.type === "offline_download" 判断。

二、长文件名的换行处理

<GridItem color="$neutral9">{props.file_name}</GridItem>

标签列加了 whiteSpace: "nowrap",但值列没有任何约束。离线下载的文件名经常很长(尤其是从 URL 或磁力链解析出来的),在窄屏或侧边栏中可能撑破网格布局。建议给值列加上 wordBreak: "break-all" 一类的处理,可以参考同文件中 url 行的现有做法保持一致。

其他已确认无误的点: getFileSize~/utils 导入正确(定义在 src/utils/str.ts);fileSize() > 0 的判断能正确过滤掉大小为 0 的情况,同时也避开了 getFileSize 对 falsy 值返回 "-" 的行为;i18n key 加在 offline_download 块内位置合适。

这两点都不是阻塞问题,第一点确认一下设计意图即可。

The file name and size are the most useful when a task has already
failed or completed - failed tasks need the recognized name and size
for diagnosis, and finished ones stay in the list the longest. The
backend persists FileName/FileSize on DownloadTask, so the fields are
still returned after the task ends.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@gengjiawen

Copy link
Copy Markdown
Author

感谢 review,两点都确认过了。

一、去掉 done === "undone" 限制 —— 已采纳

没有特别理由,就是当时想窄一点。你说的场景更合理:失败的任务最需要知道它当时识别到的文件名和体积,而且这两类任务停留在列表里的时间也更长。

后端也支持这么做:FileName / FileSizeDownloadTask 上带 json tag 的持久化字段,任务结束后不会被清空,getTaskInfo 通过 taskFileInfo 接口照样能取到,所以已完成/已失败的任务同样有值。

已改为只判断 type:

const showFileInfo = () => props.type === "offline_download"

二、长文件名换行 —— 确认已经生效,没有额外改动

这里值列其实已经有约束了:包住整个 GridVStack 设了 css={{ wordBreak: "break-all", fontSize: "0.8em" }}Task.tsx 展开视图最外层),word-break 是可继承属性,所有 GridItem 都会继承到。

而且你提到的「参考 url 行的现有做法」,url 行正是靠这个继承实现的 —— helper.tsx 里 url 只渲染了一个 <a>Task.tsx 中对应的 <GridItem color="$neutral9">{value}</GridItem> 也没有单独设 wordBreak。所以新增的 file_name 行和 url 行的处理方式本来就是一致的,再显式加一遍反而重复了。另外 grid item 默认 min-width: auto,在 break-all 下 min-content 宽度就是单个字符,不会撑破布局。

如果你在某个具体宽度下实际看到过溢出,麻烦贴个截图,我再单独排查。

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