From 1158cc4ffb95c54e654f2726fa6d9992bcb75db0 Mon Sep 17 00:00:00 2001 From: wintbit Date: Mon, 16 Jun 2025 21:46:31 +0800 Subject: [PATCH] fix: share link password display considering public url --- .../FileManager/Dialogs/Share/ShareDialog.tsx | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/src/component/FileManager/Dialogs/Share/ShareDialog.tsx b/src/component/FileManager/Dialogs/Share/ShareDialog.tsx index 664cabf..f4f8737 100644 --- a/src/component/FileManager/Dialogs/Share/ShareDialog.tsx +++ b/src/component/FileManager/Dialogs/Share/ShareDialog.tsx @@ -1,7 +1,7 @@ import { Box, DialogContent, IconButton, List, Tooltip, useTheme } from "@mui/material"; import dayjs from "dayjs"; import { TFunction } from "i18next"; -import React, { useCallback, useEffect, useState } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { CSSTransition, SwitchTransition } from "react-transition-group"; import { Share as ShareModel } from "../../../../api/explorer.ts"; @@ -22,6 +22,11 @@ const initialSetting: ShareSetting = { downloads_val: downloadOptions[0], }; +interface ShareLinkPassword { + shareLink: string; + password?: string; +} + const shareToSetting = (share: ShareModel, t: TFunction): ShareSetting => { const res: ShareSetting = { is_private: share.is_private, @@ -67,6 +72,15 @@ const ShareDialog = () => { const [loading, setLoading] = useState(false); const [setting, setSetting] = useState(initialSetting); const [shareLink, setShareLink] = useState(""); + const shareLinkPassword = useMemo(() => { + const start = shareLink.lastIndexOf("/s/"); + const shareLinkParts = shareLink.substring(start + 3).split("/"); + const password = shareLinkParts.length == 2 ? shareLinkParts[1] : undefined; + return { + shareLink: password ? shareLink.substring(0, shareLink.lastIndexOf("/")) : shareLink, + password: password, + } as ShareLinkPassword; + }, [shareLink]); const open = useAppSelector((state) => state.globalState.shareLinkDialogOpen); const target = useAppSelector((state) => state.globalState.shareLinkDialogFile); @@ -131,7 +145,13 @@ const ShareDialog = () => { maxWidth: "xs", }} cancelText={shareLink ? "common:close" : undefined} - okText={shareLink ? "fileManager.copyLinkAlongWithPassword" : undefined} + okText={ + shareLink + ? shareLinkPassword.password + ? "fileManager.copyLinkAlongWithPassword" + : "fileManager.copy" + : undefined + } secondaryAction={ shareLink ? // @ts-ignore @@ -176,7 +196,7 @@ const ShareDialog = () => { inputProps={{ readonly: true }} label={t("modals.shareLink")} fullWidth - value={shareLink.substring(0, shareLink.lastIndexOf("/"))} + value={shareLinkPassword.shareLink} onFocus={(e) => e.target.select()} slotProps={{ input: { @@ -192,29 +212,31 @@ const ShareDialog = () => { }, }} /> - e.target.select()} - slotProps={{ - input: { - endAdornment: ( - - copyToClipboard(shareLink.substring(shareLink.lastIndexOf("/") + 1) ?? "") - } - size="small" - sx={{ marginRight: -1 }} - > - - - ), - }, - }} - /> + {shareLinkPassword.password && ( + e.target.select()} + slotProps={{ + input: { + endAdornment: ( + + copyToClipboard(shareLink.substring(shareLink.lastIndexOf("/") + 1) ?? "") + } + size="small" + sx={{ marginRight: -1 }} + > + + + ), + }, + }} + /> + )} )}