Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hooks/usePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/lang/en/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/pages/home/toolbar/ModalWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Modal
blockScrollOnMount={props.blockScrollOnMount}
Expand Down
22 changes: 20 additions & 2 deletions src/pages/home/toolbar/Right.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, createDisclosure, VStack } from "@hope-ui/solid"
import { createMemo, Show } from "solid-js"
import { createMemo, onCleanup, Show } from "solid-js"
import { RightIcon } from "./Icon"
import { CgMoreO } from "solid-icons/cg"
import { TbCheckbox } from "solid-icons/tb"
Expand All @@ -15,11 +15,20 @@ import { isTocVisible, setTocDisabled } from "~/components"
import { BiSolidBookContent } from "solid-icons/bi"

export const Right = () => {
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()
Expand Down Expand Up @@ -116,6 +125,15 @@ export const Right = () => {
bus.emit("tool", "upload")
}}
/>
<Show when={objStore.can_transfer}>
<RightIcon
as={operations.transfer_share.icon}
tips="transfer_share"
onClick={() => {
bus.emit("tool", "transfer_share")
}}
/>
</Show>
</Show>
<Show
when={isFolder() && !isShare() && userCan("offline_download")}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { LocalSettings } from "./LocalSettings"
import { BackTop } from "./BackTop"
import { Decompress } from "./Decompress"
import { Share } from "./Share"
import { TransferShare } from "./TransferShare"

const Upload = lazy(() => import("../uploads/Upload"))

Expand All @@ -35,6 +36,7 @@ export const Modal = () => {
<RemoveEmptyDirectory />
<BatchRename />
<OfflineDownload />
<TransferShare />
<PackageDownloadModal />
<ModalWrapper name="upload" title="home.toolbar.upload">
<Upload />
Expand Down
74 changes: 74 additions & 0 deletions src/pages/home/toolbar/TransferShare.tsx
Original file line number Diff line number Diff line change
@@ -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<any> =>
r.post("/fs/transfer", {
url: srcUrl(),
dst_dir: pathname(),
valid_code: validCode(),
}),
)
return (
<ModalWrapper
name="transfer_share"
title={t("home.toolbar.transfer_share")}
closeName="transfer_share_modal_close"
>
<VStack spacing="$2" alignItems="start">
<Text>{t("home.toolbar.transfer_share_src_url")}</Text>
<Input
value={srcUrl()}
onInput={(e) => setSrcUrl(e.currentTarget.value)}
placeholder="https://..."
/>
<Text>{t("home.toolbar.transfer_share_valid_code")}</Text>
<Input
value={validCode()}
onInput={(e) => setValidCode(e.currentTarget.value)}
/>
</VStack>
<HStack spacing="$2" mt="$4" mb="$2" justifyContent="end">
<Button
onClick={() => {
bus.emit("tool", "transfer_share_modal_close")
}}
colorScheme="neutral"
>
{t("global.cancel")}
</Button>
<Button
loading={loading()}
onClick={async () => {
try {
if (!srcUrl()) {
throw new Error("Empty Source URL")
}
const resp = await ok()
handleRespWithNotifySuccess(resp, () => {
refresh()
})
} catch (e) {
notify.error((e as Error).message)
} finally {
setSrcUrl("")
setValidCode("")
bus.emit("tool", "transfer_share_modal_close")
}
}}
>
{t("global.confirm")}
</Button>
</HStack>
</ModalWrapper>
)
}
3 changes: 2 additions & 1 deletion src/pages/home/toolbar/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/store/obj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ const initialObjStore = {
header: "",
provider: "",
direct_upload_tools: <string[] | undefined>undefined,
can_transfer: false,
state: State.Initial,
err: "",
write: <boolean | undefined>undefined,
}
const [objStore, setObjStore] = createStore<
typeof initialObjStore & {
write?: boolean
}
>(initialObjStore)
const [objStore, setObjStore] = createStore(initialObjStore)

const setObjs = (objs: Obj[]) => {
lastChecked.start = -1
Expand Down Expand Up @@ -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),
}

Expand Down
1 change: 1 addition & 0 deletions src/types/resp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type FsListResp = Resp<{
write: boolean
provider: string
direct_upload_tools?: string[]
can_transfer: boolean
}>

export type SearchNode = {
Expand Down