From 6cb6af84d2b728453dd0d14cc988b454a5ea2ca4 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Mon, 6 Nov 2023 16:53:06 +0800 Subject: [PATCH] feat: adapt the new task api (#120) * wip: adapt new api * Squashed commit of the following: commit 82869dd2eb85e064990f00b302f35ae966852508 Author: Andy Hsu Date: Thu Oct 26 19:25:16 2023 +0800 chore: change ts query key commit 1243b9fb719fbc5e1989e811cd0b9516218ba7a3 Author: Isla Date: Thu Oct 26 11:24:14 2023 +0000 style: format code with prettier commit 4f7d9c8e533a261a2aa37059d78a50e81251f81e Author: IlaBot Date: Thu Oct 26 11:23:31 2023 +0000 chore: auto update i18n file commit d7febf8e0e4d4cd311ce0e2948ab29680b9b31b3 Author: Andy Hsu Date: Sun Oct 22 20:39:01 2023 +0800 fix: missing font of katex (close alist-org/alist#5417) commit ab6701c50c88f8439464bf598788d1a01f4253c3 Author: Andy Hsu Date: Sun Oct 22 19:05:48 2023 +0800 feat: add shortcut for text save (close alist-org/alist#5396) commit 04d98e9cbb404f9f08ae51d6fae90a888f44709c Author: Isla Date: Thu Oct 12 13:00:33 2023 +0000 style: format code with prettier commit cb4ee2177db4a92ce832e03eb45d71292f792445 Author: IlaBot Date: Thu Oct 12 12:59:48 2023 +0000 chore: auto update i18n file * chore: main updates (#119) * chore: auto update i18n file * style: format code with prettier * feat: add shortcut for text save (close alist-org/alist#5396) * fix: missing font of katex (close alist-org/alist#5417) * chore: auto update i18n file * style: format code with prettier * chore: change ts query key * chore: auto update i18n file * style: format code with prettier * fix: package download setting does not take effect (close alist-org/alist#5478) * feat: audio player use list order by default (#115) --------- Co-authored-by: IlaBot Co-authored-by: 22 <60903333+nini22P@users.noreply.github.com> --------- Co-authored-by: IlaBot Co-authored-by: 22 <60903333+nini22P@users.noreply.github.com> --- src/lang/en/manage.json | 5 ++- src/lang/en/tasks.json | 6 ++-- src/pages/home/toolbar/OfflineDownload.tsx | 40 +++++++++++++++------ src/pages/manage/sidemenu_items.tsx | 27 ++++++++------ src/pages/manage/tasks/offline_download.tsx | 15 ++++++++ src/utils/api.ts | 4 +-- 6 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 src/pages/manage/tasks/offline_download.tsx diff --git a/src/lang/en/manage.json b/src/lang/en/manage.json index 3596b996d2..5268eb2441 100644 --- a/src/lang/en/manage.json +++ b/src/lang/en/manage.json @@ -13,15 +13,14 @@ "profile": "Profile", "about": "About", "tasks": "Tasks", - "aria2": "Aria2", "upload": "Upload", "copy": "Copy", "backup-restore": "Backup & Restore", "home": "Home", "indexes": "Indexes", "sso": "Single Sign-on", - "qbit": "qBittorrent", - "docs": "Documentation" + "docs": "Documentation", + "offline_download": "Offline Download" }, "title": "AList Manage", "not_admin": "You are not admin user, please login with admin account.", diff --git a/src/lang/en/tasks.json b/src/lang/en/tasks.json index 2aee45fa97..ef8ea956d4 100644 --- a/src/lang/en/tasks.json +++ b/src/lang/en/tasks.json @@ -1,8 +1,6 @@ { - "aria2_down": "Download file to local machine", - "aria2_transfer": "Transfer downloaded file to corresponding storage", - "qbit_down": "Download file to local machine", - "qbit_transfer": "Transfer downloaded file to corresponding storage", + "offline_download": "Download file to local machine", + "offline_download_transfer": "Transfer downloaded file to corresponding storage", "upload": "Upload file to corresponding storage", "copy": "Copy file from a storage to another storage", "done": "Completed", diff --git a/src/pages/home/toolbar/OfflineDownload.tsx b/src/pages/home/toolbar/OfflineDownload.tsx index 717ac73e75..521056ee98 100644 --- a/src/pages/home/toolbar/OfflineDownload.tsx +++ b/src/pages/home/toolbar/OfflineDownload.tsx @@ -1,12 +1,31 @@ import { Box, createDisclosure } from "@hope-ui/solid" import { ModalInput, SelectWrapper } from "~/components" import { useFetch, useRouter, useT } from "~/hooks" -import { offlineDownload, bus, handleRespWithNotifySuccess } from "~/utils" -import { createSignal, onCleanup } from "solid-js" +import { + offlineDownload, + bus, + handleRespWithNotifySuccess, + r, + handleResp, +} from "~/utils" +import { createSignal, onCleanup, onMount } from "solid-js" +import { PResp } from "~/types" export const OfflineDownload = () => { const t = useT() - const [type, setType] = createSignal("aria2") + const [tools, setTools] = createSignal([] as string[]) + const [toolsLoading, reqTool] = useFetch((): PResp => { + return r.get("/public/offline_download_tools") + }) + const [tool, setTool] = createSignal("") + onMount(async () => { + const resp = await reqTool() + handleResp(resp, (data) => { + setTools(data) + setTool(data[0]) + }) + }) + const { isOpen, onOpen, onClose } = createDisclosure() const [loading, ok] = useFetch(offlineDownload) const { pathname } = useRouter() @@ -25,22 +44,21 @@ export const OfflineDownload = () => { type="text" opened={isOpen()} onClose={onClose} - loading={loading()} + loading={toolsLoading() || loading()} tips={t("home.toolbar.offline_download-tips")} topSlot={ setType(v)} - options={[ - { value: "aria2", label: "Aria2" }, - { value: "qbit", label: "qBittorrent" }, - ]} + value={tool()} + onChange={(v) => setTool(v)} + options={tools().map((tool) => { + return { value: tool, label: tool } + })} /> } onSubmit={async (urls) => { - const resp = await ok(pathname(), urls.split("\n"), type()) + const resp = await ok(pathname(), urls.split("\n"), tool()) handleRespWithNotifySuccess(resp, () => { onClose() }) diff --git a/src/pages/manage/sidemenu_items.tsx b/src/pages/manage/sidemenu_items.tsx index 2b7a3e060f..c0008ab41e 100644 --- a/src/pages/manage/sidemenu_items.tsx +++ b/src/pages/manage/sidemenu_items.tsx @@ -9,7 +9,6 @@ import { BsMedium, BsFingerprint, BsFront, - BsCloudArrowDownFill, BsCloudUploadFill, BsSearch, } from "solid-icons/bs" @@ -17,7 +16,7 @@ import { FiLogIn } from "solid-icons/fi" import { SiMetabase } from "solid-icons/si" import { CgDatabase } from "solid-icons/cg" import { OcWorkflow2 } from "solid-icons/oc" -import { IoCopy, IoHome } from "solid-icons/io" +import { IoCopy, IoHome, IoMagnetOutline } from "solid-icons/io" import { Component, lazy } from "solid-js" import { Group, UserRole } from "~/types" import { FaBrandsQuinscape, FaSolidBook, FaSolidDatabase } from "solid-icons/fa" @@ -86,17 +85,23 @@ export const side_menu_items: SideMenuItem[] = [ to: "/@manage/tasks", children: [ { - title: "manage.sidemenu.aria2", - icon: BsCloudArrowDownFill, + title: "manage.sidemenu.offline_download", + icon: IoMagnetOutline, to: "/@manage/tasks/aria2", - component: lazy(() => import("./tasks/Aria2")), - }, - { - title: "manage.sidemenu.qbit", - icon: FaBrandsQuinscape, - to: "/@manage/tasks/qbit", - component: lazy(() => import("./tasks/Qbit")), + component: lazy(() => import("./tasks/offline_download")), }, + // { + // title: "manage.sidemenu.aria2", + // icon: BsCloudArrowDownFill, + // to: "/@manage/tasks/aria2", + // component: lazy(() => import("./tasks/Aria2")), + // }, + // { + // title: "manage.sidemenu.qbit", + // icon: FaBrandsQuinscape, + // to: "/@manage/tasks/qbit", + // component: lazy(() => import("./tasks/Qbit")), + // }, { title: "manage.sidemenu.upload", icon: BsCloudUploadFill, diff --git a/src/pages/manage/tasks/offline_download.tsx b/src/pages/manage/tasks/offline_download.tsx new file mode 100644 index 0000000000..8c6f37924e --- /dev/null +++ b/src/pages/manage/tasks/offline_download.tsx @@ -0,0 +1,15 @@ +import { VStack } from "@hope-ui/solid" +import { useManageTitle } from "~/hooks" +import { TypeTasks } from "./Tasks" + +const OfflineDownload = () => { + useManageTitle("manage.sidemenu.offline_download") + return ( + + + + + ) +} + +export default OfflineDownload diff --git a/src/utils/api.ts b/src/utils/api.ts index 390ab5fc9a..5ccf30c474 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -108,9 +108,9 @@ export const fsNewFile = (path: string, password: string): PEmptyResp => { export const offlineDownload = ( path: string, urls: string[], - type: string, + tool: string, ): PEmptyResp => { - return r.post(`/fs/add_${type}`, { path, urls }) + return r.post(`/fs/add_offline_download`, { path, urls, tool }) } export const fetchText = async (