diff --git a/src/hooks/usePath.ts b/src/hooks/usePath.ts index 230f94758..85cf6b19e 100644 --- a/src/hooks/usePath.ts +++ b/src/hooks/usePath.ts @@ -178,6 +178,7 @@ export const usePath = () => { ObjStore.setWrite(data.write) ObjStore.setProvider(data.provider) ObjStore.setDirectUploadTools(data.direct_upload_tools) + ObjStore.setCanTransfer(data.can_transfer) ObjStore.setState(State.Folder) }, handleErr, diff --git a/src/lang/en/home.json b/src/lang/en/home.json index 29c30a0e7..80781214d 100644 --- a/src/lang/en/home.json +++ b/src/lang/en/home.json @@ -68,6 +68,9 @@ "input_filename": "Input filename", "cancel_select": "Cancel Select", "offline_download": "Offline download", + "transfer_share": "Transfer Share", + "transfer_share_src_url": "Source URL", + "transfer_share_valid_code": "Valid Code (Optional)", "offline_download-tips": "One URL per line", "delete_policy": { "delete_on_upload_succeed": "Delete on upload succeed", diff --git a/src/pages/home/toolbar/ModalWrapper.tsx b/src/pages/home/toolbar/ModalWrapper.tsx index 19b91ef7d..d6b580731 100644 --- a/src/pages/home/toolbar/ModalWrapper.tsx +++ b/src/pages/home/toolbar/ModalWrapper.tsx @@ -17,18 +17,21 @@ export const ModalWrapper = (props: { name: string title: string blockScrollOnMount?: boolean + closeName?: string }) => { const t = useT() + const { isOpen, onOpen, onClose } = createDisclosure() const handler = (name: string) => { if (name === props.name) { onOpen() + } else if (props.closeName && name === props.closeName) { + onClose() } } bus.on("tool", handler) onCleanup(() => { bus.off("tool", handler) }) - const { isOpen, onOpen, onClose } = createDisclosure() return ( { - const { isOpen, onToggle } = createDisclosure({ + const { isOpen, onToggle, onClose } = createDisclosure({ defaultIsOpen: localStorage.getItem("more-open") === "true", onClose: () => localStorage.setItem("more-open", "false"), onOpen: () => localStorage.setItem("more-open", "true"), }) + const handler = (name: string) => { + if (name === "close_right_toolbar") { + onClose() + } + } + bus.on("tool", handler) + onCleanup(() => { + bus.off("tool", handler) + }) const margin = createMemo(() => (isOpen() ? "$4" : "$5")) const isFolder = createMemo(() => objStore.state === State.Folder) const { refresh } = usePath() @@ -116,6 +125,15 @@ export const Right = () => { bus.emit("tool", "upload") }} /> + + { + bus.emit("tool", "transfer_share") + }} + /> + import("../uploads/Upload")) @@ -35,6 +36,7 @@ export const Modal = () => { + diff --git a/src/pages/home/toolbar/TransferShare.tsx b/src/pages/home/toolbar/TransferShare.tsx new file mode 100644 index 000000000..01a577a40 --- /dev/null +++ b/src/pages/home/toolbar/TransferShare.tsx @@ -0,0 +1,74 @@ +import { Button, HStack, Input, Text, VStack } from "@hope-ui/solid" +import { createSignal } from "solid-js" +import { useFetch, usePath, useRouter, useT } from "~/hooks" +import { bus, handleRespWithNotifySuccess, notify, r } from "~/utils" +import { ModalWrapper } from "./ModalWrapper" + +export const TransferShare = () => { + const t = useT() + const { refresh } = usePath() + const { pathname } = useRouter() + const [srcUrl, setSrcUrl] = createSignal("") + const [validCode, setValidCode] = createSignal("") + const [loading, ok] = useFetch( + (): Promise => + r.post("/fs/transfer", { + url: srcUrl(), + dst_dir: pathname(), + valid_code: validCode(), + }), + ) + return ( + + + {t("home.toolbar.transfer_share_src_url")} + setSrcUrl(e.currentTarget.value)} + placeholder="https://..." + /> + {t("home.toolbar.transfer_share_valid_code")} + setValidCode(e.currentTarget.value)} + /> + + + + + + + ) +} diff --git a/src/pages/home/toolbar/operations.ts b/src/pages/home/toolbar/operations.ts index 2f50c4976..2e475af1e 100644 --- a/src/pages/home/toolbar/operations.ts +++ b/src/pages/home/toolbar/operations.ts @@ -7,7 +7,7 @@ import { AiTwotoneDelete } from "solid-icons/ai" import { CgFileAdd, CgFolderAdd, CgFolderRemove } from "solid-icons/cg" import { AiOutlineCloudDownload } from "solid-icons/ai" import { ImMoveUp } from "solid-icons/im" -import { BiRegularRename } from "solid-icons/bi" +import { BiRegularRename, BiRegularTransfer } from "solid-icons/bi" export interface Operations { [key: string]: { @@ -31,6 +31,7 @@ export const operations: Operations = { cancel_select: { icon: TiDeleteOutline }, download: { icon: AiOutlineCloudDownload, color: "$primary9" }, share: { icon: CgShare, color: "$primary9" }, + transfer_share: { icon: BiRegularTransfer, p: true }, } // interface Operation { // label: string; diff --git a/src/store/obj.ts b/src/store/obj.ts index b39d34d89..1e76b867c 100644 --- a/src/store/obj.ts +++ b/src/store/obj.ts @@ -29,14 +29,12 @@ const initialObjStore = { header: "", provider: "", direct_upload_tools: undefined, + can_transfer: false, state: State.Initial, err: "", + write: undefined, } -const [objStore, setObjStore] = createStore< - typeof initialObjStore & { - write?: boolean - } ->(initialObjStore) +const [objStore, setObjStore] = createStore(initialObjStore) const setObjs = (objs: Obj[]) => { lastChecked.start = -1 @@ -79,6 +77,8 @@ export const ObjStore = { setState: (state: State) => setObjStore("state", state), setDirectUploadTools: (tools?: string[]) => setObjStore("direct_upload_tools", tools), + setCanTransfer: (canTransfer: boolean) => + setObjStore("can_transfer", canTransfer), setErr: (err: string) => setObjStore("err", err), } diff --git a/src/types/resp.ts b/src/types/resp.ts index 397e39a07..f03590534 100644 --- a/src/types/resp.ts +++ b/src/types/resp.ts @@ -19,6 +19,7 @@ export type FsListResp = Resp<{ write: boolean provider: string direct_upload_tools?: string[] + can_transfer: boolean }> export type SearchNode = {