-
Notifications
You must be signed in to change notification settings - Fork 155
feat(offline_download): add task progress list #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zwzzrl
wants to merge
13
commits into
OpenListTeam:main
Choose a base branch
from
zwzzrl:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−39
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
75fcca7
添加离线下载任务列表
zwzzrl a0395ee
添加离线下载任务列表二
zwzzrl 94c1b8a
触发Actions
zwzzrl f35d752
Revert "触发Actions"
zwzzrl 0088ad9
pnpm format
xrgzs 4c2c68d
修复定时器设置,确保使用 window.setInterval
xrgzs 4e3b205
删除重复代码并优化逻辑
zwzzrl e642985
移动文件位置
xrgzs e3e411a
pnpm format
xrgzs 1ab5476
优化导入路径,修复文件名显示和状态颜色处理
xrgzs 5189a48
修复进度条值的计算,直接使用 props.progress
xrgzs 13d40d3
修改函数名
zwzzrl c2b905a
Merge branch 'OpenListTeam:main' into main
zwzzrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { | ||
| VStack, | ||
| HStack, | ||
| Text, | ||
| Badge, | ||
| Progress, | ||
| ProgressIndicator, | ||
| } from "@hope-ui/solid" | ||
| import type { TaskInfo } from "~/types" | ||
| import { getFileSize } from "~/utils" | ||
| import { Show } from "solid-js" | ||
| import { useT } from "~/hooks" | ||
| import { getPath } from "~/pages/manage/tasks/helper" | ||
|
|
||
| // 解析任务名称,返回文件名和路径信息 | ||
| const parseTaskName = (name: string) => { | ||
| // download 类型:download 文件名 to (路径) | ||
| let match = name.match(/^download (.+) to \((.+)\)$/) | ||
| if (match) { | ||
| return { | ||
| type: "download" as const, | ||
| fileName: match[1], | ||
| path: match[2], | ||
| } | ||
| } | ||
| // transfer/upload 类型:transfer [设备](路径) to [目标设备](目标路径) 或 upload [文件名](URL) to [目标设备](目标路径) | ||
| match = name.match( | ||
| /^(transfer|upload) \[(.*?)\]\((.*?)\) to \[(.*?)\]\((.*?)\)$/, | ||
| ) | ||
| if (match) { | ||
| const type = match[1] as "transfer" | "upload" | ||
| const bracketContent = match[2] // 方括号内:transfer 为设备,upload 为文件名 | ||
| const urlOrPath = match[3] // 圆括号内:transfer 为路径,upload 为 URL | ||
| const dstDevice = match[4] | ||
| const dstPath = match[5] | ||
|
|
||
| if (type === "transfer") { | ||
| // 从路径中提取文件名(最后一段,去除参数) | ||
| const fileName = | ||
| urlOrPath.split("/").pop()?.split("?")[0] || "Unknown file" | ||
| return { | ||
| type, | ||
| fileName, | ||
| srcDevice: bracketContent, | ||
| srcPath: urlOrPath, | ||
| dstDevice, | ||
| dstPath, | ||
| } | ||
| } else { | ||
| // upload 类型:文件名直接取自方括号 | ||
| return { | ||
| type, | ||
| fileName: bracketContent, | ||
| srcDevice: "", | ||
| srcPath: urlOrPath, | ||
| dstDevice, | ||
| dstPath, | ||
| } | ||
| } | ||
| } | ||
| return null | ||
| } | ||
|
|
||
| export const StatusColor = { | ||
| 0: "neutral", | ||
| 1: "info", | ||
| 2: "warning", | ||
| 3: "danger", | ||
| 4: "success", | ||
| 5: "info", | ||
| } as const | ||
|
|
||
| export const OfflineDownloadTaskItem = (props: TaskInfo) => { | ||
| const t = useT() | ||
| const parsed = parseTaskName(props.name) | ||
|
|
||
| return ( | ||
| <VStack | ||
| w="$full" | ||
| spacing="$1" | ||
| rounded="$lg" | ||
| border="1px solid $neutral7" | ||
| alignItems="start" | ||
| p="$2" | ||
| _hover={{ border: "1px solid $info6" }} | ||
| > | ||
| {parsed ? ( | ||
| <> | ||
| <Text css={{ wordBreak: "break-all" }}>{parsed.fileName}</Text> | ||
| {parsed.type === "download" && parsed.path && ( | ||
| <Text css={{ wordBreak: "break-all" }} size="sm" color="$neutral11"> | ||
| {t("tasks.attr.offline_download.path")}:{" "} | ||
| {getPath("", parsed.path)} | ||
| </Text> | ||
| )} | ||
| {parsed.type === "transfer" && parsed.dstPath && ( | ||
| <Text css={{ wordBreak: "break-all" }} size="sm" color="$neutral11"> | ||
| {t("tasks.attr.offline_download.transfer_dst")}:{" "} | ||
| {getPath(parsed.dstDevice, parsed.dstPath)} | ||
| </Text> | ||
| )} | ||
| {parsed.type === "upload" && parsed.dstPath && ( | ||
| <Text css={{ wordBreak: "break-all" }} size="sm" color="$neutral11"> | ||
| {t("tasks.attr.offline_download.path")}:{" "} | ||
| {getPath(parsed.dstDevice, parsed.dstPath)} | ||
| </Text> | ||
| )} | ||
| </> | ||
| ) : ( | ||
| <Text css={{ wordBreak: "break-all" }}>{props.name}</Text> | ||
| )} | ||
| <HStack spacing="$2" w="$full" justifyContent="space-between"> | ||
| <Badge | ||
| colorScheme={ | ||
| StatusColor[props.state as keyof typeof StatusColor] ?? "info" | ||
| } | ||
| > | ||
| {t("tasks.state." + props.state)} | ||
| </Badge> | ||
| <Text color="$neutral11">{getFileSize(props.total_bytes)}</Text> | ||
| </HStack> | ||
| <Progress | ||
| w="$full" | ||
| trackColor="$info3" | ||
| rounded="$full" | ||
| value={props.progress} | ||
| size="sm" | ||
| > | ||
| <ProgressIndicator color="$info6" rounded="$md" /> | ||
| </Progress> | ||
| <Show when={props.error}> | ||
| <Text color="$danger10" css={{ wordBreak: "break-all" }}> | ||
| {props.error} | ||
| </Text> | ||
| </Show> | ||
| </VStack> | ||
| ) | ||
| } | ||
|
|
||
| export default OfflineDownloadTaskItem | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.