Skip to content

Commit

Permalink
feat: support general users view and cancel own tasks (#201)
Browse files Browse the repository at this point in the history
(frontend part of AlistGo/alist/#7398)

1. Add a creator attribute to the upload, copy and offline download
tasks, so that a GENERAL task creator can view and cancel them. The
creator will be displayed over the task state in the form of a Badge.
2. Transfer call on `/admin/task` to `/task`
  • Loading branch information
KirCute authored Nov 1, 2024
1 parent 19170f6 commit f5a05a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/pages/manage/sidemenu_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export const side_menu_items: SideMenuItem[] = [
title: "manage.sidemenu.tasks",
icon: OcWorkflow2,
to: "/@manage/tasks",
role: UserRole.GENERAL,
children: [
{
title: "manage.sidemenu.offline_download",
icon: IoMagnetOutline,
to: "/@manage/tasks/aria2",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/offline_download")),
},
// {
Expand All @@ -119,12 +121,14 @@ export const side_menu_items: SideMenuItem[] = [
title: "manage.sidemenu.upload",
icon: BsCloudUploadFill,
to: "/@manage/tasks/upload",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/Upload")),
},
{
title: "manage.sidemenu.copy",
icon: IoCopy,
to: "/@manage/tasks/copy",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/Copy")),
},
],
Expand Down
12 changes: 10 additions & 2 deletions src/pages/manage/tasks/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const StateMap: Record<
[TaskStateEnum.Succeeded]: "success",
[TaskStateEnum.Canceled]: "neutral",
}

const Creator = (props: { name: string; role: number }) => {
if (props.role < 0) return null
const roleColors = ["info", "neutral", "accent"]
return <Badge colorScheme={roleColors[props.role] as any}>{props.name}</Badge>
}

export const TaskState = (props: { state: number }) => {
const t = useT()
return (
Expand All @@ -58,10 +65,10 @@ export const Task = (props: TaskInfo & TasksProps) => {
const canRetry = props.done === "done" && props.state === TaskStateEnum.Failed
const [operateLoading, operate] = useFetch(
(): PEmptyResp =>
r.post(`/admin/task/${props.type}/${operateName}?tid=${props.id}`),
r.post(`/task/${props.type}/${operateName}?tid=${props.id}`),
)
const [retryLoading, retry] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/retry?tid=${props.id}`),
(): PEmptyResp => r.post(`/task/${props.type}/retry?tid=${props.id}`),
)
const [deleted, setDeleted] = createSignal(false)
return (
Expand All @@ -85,6 +92,7 @@ export const Task = (props: TaskInfo & TasksProps) => {
>
{props.name}
</Heading>
<Creator name={props.creator} role={props.creator_role} />
<TaskState state={props.state} />
<Text
css={{
Expand Down
8 changes: 4 additions & 4 deletions src/pages/manage/tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface TasksProps {
export const Tasks = (props: TasksProps) => {
const t = useT()
const [loading, get] = useFetch(
(): PResp<TaskInfo[]> => r.get(`/admin/task/${props.type}/${props.done}`),
(): PResp<TaskInfo[]> => r.get(`/task/${props.type}/${props.done}`),
)
const [tasks, setTasks] = createSignal<TaskInfo[]>([])
const refresh = async () => {
Expand All @@ -36,13 +36,13 @@ export const Tasks = (props: TasksProps) => {
onCleanup(() => clearInterval(interval))
}
const [clearDoneLoading, clearDone] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/clear_done`),
(): PEmptyResp => r.post(`/task/${props.type}/clear_done`),
)
const [clearSucceededLoading, clearSucceeded] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/clear_succeeded`),
(): PEmptyResp => r.post(`/task/${props.type}/clear_succeeded`),
)
const [retryFailedLoading, retryFailed] = useFetch(
(): PEmptyResp => r.post(`/admin/task/${props.type}/retry_failed`),
(): PEmptyResp => r.post(`/task/${props.type}/retry_failed`),
)
const [page, setPage] = createSignal(1)
const pageSize = 20
Expand Down
2 changes: 2 additions & 0 deletions src/types/task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface TaskInfo {
id: string
name: string
creator: string
creator_role: number
state: number
status: string
progress: number
Expand Down

0 comments on commit f5a05a6

Please sign in to comment.