Skip to content

Commit

Permalink
feat(offline-download): allow using offline download tools in any sto…
Browse files Browse the repository at this point in the history
…rage (#218)

* Feat(offline-download): allow using thunder offline download tool in any storage

* Feat(offline-download): allow using 115 offline download tool in any storage

* Feat(offline-download): allow using pikpak offline download tool in any storage
  • Loading branch information
Lanfei authored Jan 10, 2025
1 parent a1b2d99 commit d67283e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/lang/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
"sso_organization_name": "Sso organization name",
"text_types": "Text types",
"token": "Token",
"115_temp_dir": "115 temp dir",
"pikpak_temp_dir": "PikPak temp dir",
"thunder_temp_dir": "Thunder temp dir",
"transmission_seedtime": "Transmission seedtime",
"transmission_uri": "Transmission uri",
"version": "Version",
Expand Down
8 changes: 7 additions & 1 deletion src/lang/en/settings_other.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
"set_qbit": "Set qBittorrent",
"qbittorrent": "qBittorrent",
"transmission": "Transmission",
"set_transmission": "Set Transmission"
"set_transmission": "Set Transmission",
"115": "115",
"set_115": "Set 115",
"pikpak": "PikPak",
"set_pikpak": "Set PikPak",
"thunder": "Thunder",
"set_thunder": "Set Thunder"
}
109 changes: 107 additions & 2 deletions src/pages/manage/settings/Other.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Button, Heading, HStack, Input, SimpleGrid } from "@hope-ui/solid"
import {
Button,
FormControl,
FormLabel,
Heading,
HStack,
Input,
SimpleGrid,
} from "@hope-ui/solid"
import { createSignal } from "solid-js"
import { MaybeLoading } from "~/components"
import { FolderChooseInput, MaybeLoading } from "~/components"
import { useFetch, useManageTitle, useT, useUtil } from "~/hooks"
import { Group, SettingItem, PResp } from "~/types"
import { handleResp, notify, r } from "~/utils"
Expand All @@ -15,6 +23,9 @@ const OtherSettings = () => {
const [qbitSeedTime, setQbitSeedTime] = createSignal("")
const [transmissionUrl, setTransmissionUrl] = createSignal("")
const [transmissionSeedTime, setTransmissionSeedTime] = createSignal("")
const [pan115TempDir, set115TempDir] = createSignal("")
const [pikpakTempDir, setPikPakTempDir] = createSignal("")
const [thunderTempDir, setThunderTempDir] = createSignal("")
const [token, setToken] = createSignal("")
const [settings, setSettings] = createSignal<SettingItem[]>([])
const [settingsLoading, settingsData] = useFetch(
Expand All @@ -39,6 +50,24 @@ const OtherSettings = () => {
seedtime: transmissionSeedTime(),
}),
)
const [set115Loading, set115] = useFetch(
(): PResp<string> =>
r.post("/admin/setting/set_115", {
temp_dir: pan115TempDir(),
}),
)
const [setPikPakLoading, setPikPak] = useFetch(
(): PResp<string> =>
r.post("/admin/setting/set_pikpak", {
temp_dir: pikpakTempDir(),
}),
)
const [setThunderLoading, setThunder] = useFetch(
(): PResp<string> =>
r.post("/admin/setting/set_thunder", {
temp_dir: thunderTempDir(),
}),
)
const refresh = async () => {
const resp = await settingsData()
handleResp(resp, (data) => {
Expand All @@ -55,6 +84,13 @@ const OtherSettings = () => {
setTransmissionSeedTime(
data.find((i) => i.key === "transmission_seedtime")?.value || "",
)
set115TempDir(data.find((i) => i.key === "115_temp_dir")?.value || "")
setPikPakTempDir(
data.find((i) => i.key === "pikpak_temp_dir")?.value || "",
)
setThunderTempDir(
data.find((i) => i.key === "thunder_temp_dir")?.value || "",
)
setSettings(data)
})
}
Expand Down Expand Up @@ -141,6 +177,75 @@ const OtherSettings = () => {
>
{t("settings_other.set_transmission")}
</Button>
<Heading my="$2">{t("settings_other.115")}</Heading>
<FormControl w="$full" display="flex" flexDirection="column">
<FormLabel for="115_temp_dir" display="flex" alignItems="center">
{t(`settings.115_temp_dir`)}
</FormLabel>
<FolderChooseInput
id="115_temp_dir"
value={pan115TempDir()}
onChange={(path) => set115TempDir(path)}
/>
</FormControl>
<Button
my="$2"
loading={set115Loading()}
onClick={async () => {
const resp = await set115()
handleResp(resp, (data) => {
notify.success(data)
})
}}
>
{t("settings_other.set_115")}
</Button>
<Heading my="$2">{t("settings_other.pikpak")}</Heading>
<FormControl w="$full" display="flex" flexDirection="column">
<FormLabel for="pikpak_temp_dir" display="flex" alignItems="center">
{t(`settings.pikpak_temp_dir`)}
</FormLabel>
<FolderChooseInput
id="pikpak_temp_dir"
value={pikpakTempDir()}
onChange={(path) => setPikPakTempDir(path)}
/>
</FormControl>
<Button
my="$2"
loading={setPikPakLoading()}
onClick={async () => {
const resp = await setPikPak()
handleResp(resp, (data) => {
notify.success(data)
})
}}
>
{t("settings_other.set_pikpak")}
</Button>
<Heading my="$2">{t("settings_other.thunder")}</Heading>
<FormControl w="$full" display="flex" flexDirection="column">
<FormLabel for="thunder_temp_dir" display="flex" alignItems="center">
{t(`settings.thunder_temp_dir`)}
</FormLabel>
<FolderChooseInput
id="thunder_temp_dir"
value={thunderTempDir()}
onChange={(path) => setThunderTempDir(path)}
/>
</FormControl>
<Button
my="$2"
loading={setThunderLoading()}
onClick={async () => {
const resp = await setThunder()
handleResp(resp, (data) => {
notify.success(data)
})
}}
>
{t("settings_other.set_thunder")}
</Button>
<Heading my="$2">{t("settings.token")}</Heading>
<Input value={token()} readOnly />
<HStack my="$2" spacing="$2">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/manage/sidemenu_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const side_menu_items: SideMenuItem[] = [
{
title: "manage.sidemenu.offline_download",
icon: IoMagnetOutline,
to: "/@manage/tasks/aria2",
to: "/@manage/tasks/offline_download",
role: UserRole.GENERAL,
component: lazy(() => import("./tasks/offline_download")),
},
Expand Down
19 changes: 11 additions & 8 deletions src/pages/manage/tasks/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { me } from "~/store"
import { TaskNameAnalyzer } from "./Tasks"
import { useT } from "~/hooks"

export const getPath = (device: string, path: string): JSX.Element => {
export const getPath = (
device: string,
path: string,
asLink: boolean = true,
): JSX.Element => {
const fullPath = (device === "/" ? "" : device) + path
const prefix = me().base_path === "/" ? "" : me().base_path
const accessible = fullPath.startsWith(prefix)
const [underline, setUnderline] = createSignal(false)
return accessible ? (
return accessible && asLink ? (
<a
style={underline() ? "text-decoration: underline" : ""}
onMouseOver={() => setUnderline(true)}
Expand Down Expand Up @@ -49,14 +53,13 @@ export const getOfflineDownloadNameAnalyzer = (): TaskNameAnalyzer => {
export const getOfflineDownloadTransferNameAnalyzer = (): TaskNameAnalyzer => {
const t = useT()
return {
regex: /^transfer ((?:.*\/)?(.+)) to \[(.+)]$/,
title: (matches) => matches[2],
regex: /^transfer \[(.*)]\((.*\/([^\/]+))\) to \[(.+)]\((.+)\)$/,
title: (matches) => matches[3],
attrs: {
[t(`tasks.attr.offline_download.transfer_src`)]: (matches) => (
<p>{matches[1]}</p>
),
[t(`tasks.attr.offline_download.transfer_src`)]: (matches) =>
getPath(matches[1], matches[2], false),
[t(`tasks.attr.offline_download.transfer_dst`)]: (matches) =>
getPath("", matches[3]),
getPath(matches[4], matches[5]),
},
}
}

0 comments on commit d67283e

Please sign in to comment.