mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-25 19:52:48 +00:00
fix: share link password display considering public url
This commit is contained in:
parent
1ec270194b
commit
1158cc4ffb
|
|
@ -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<ShareSetting>(initialSetting);
|
||||
const [shareLink, setShareLink] = useState<string>("");
|
||||
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 = () => {
|
|||
},
|
||||
}}
|
||||
/>
|
||||
<FilledTextField
|
||||
variant={"filled"}
|
||||
inputProps={{ readonly: true }}
|
||||
label={t("modals.sharePassword")}
|
||||
fullWidth
|
||||
value={shareLink.substring(shareLink.lastIndexOf("/") + 1)}
|
||||
onFocus={(e) => e.target.select()}
|
||||
slotProps={{
|
||||
input: {
|
||||
endAdornment: (
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
copyToClipboard(shareLink.substring(shareLink.lastIndexOf("/") + 1) ?? "")
|
||||
}
|
||||
size="small"
|
||||
sx={{ marginRight: -1 }}
|
||||
>
|
||||
<CopyOutlined />
|
||||
</IconButton>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
{shareLinkPassword.password && (
|
||||
<FilledTextField
|
||||
variant={"filled"}
|
||||
inputProps={{ readonly: true }}
|
||||
label={t("modals.sharePassword")}
|
||||
fullWidth
|
||||
value={shareLinkPassword.password}
|
||||
onFocus={(e) => e.target.select()}
|
||||
slotProps={{
|
||||
input: {
|
||||
endAdornment: (
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
copyToClipboard(shareLink.substring(shareLink.lastIndexOf("/") + 1) ?? "")
|
||||
}
|
||||
size="small"
|
||||
sx={{ marginRight: -1 }}
|
||||
>
|
||||
<CopyOutlined />
|
||||
</IconButton>
|
||||
),
|
||||
},
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</List>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
Loading…
Reference in New Issue