From 13ddb74aca94eb7b5dac5beaeadde89e12c904fd Mon Sep 17 00:00:00 2001 From: wintbit Date: Sun, 15 Jun 2025 21:49:57 +0800 Subject: [PATCH] feat: custom password checkbox & password display box --- public/locales/en-US/application.json | 3 +- public/locales/ja-JP/application.json | 3 +- public/locales/zh-CN/application.json | 3 +- public/locales/zh-TW/application.json | 3 +- .../FileManager/Dialogs/Share/ShareDialog.tsx | 65 +++++++++++++++---- .../Dialogs/Share/ShareSetting.tsx | 49 +++++++++----- 6 files changed, 93 insertions(+), 33 deletions(-) diff --git a/public/locales/en-US/application.json b/public/locales/en-US/application.json index 801cb51..7011377 100644 --- a/public/locales/en-US/application.json +++ b/public/locales/en-US/application.json @@ -307,6 +307,7 @@ "createShareLink": "Share", "viewDetails": "View details", "copy": "Copy", + "copyLinkAlongWithPassword": "Copy link and password", "bytes": " ({{bytes}} Bytes)", "storagePolicy": "Storage policy", "childFolders": "Child folders", @@ -469,7 +470,7 @@ "createShareLink": "Create share link", "privateShare": "Hide from public", "privateShareDes": "If selected, other people cannot see this share link on your homepage.", - "passwordPrefix": "Share link password: ", + "useCustomPassword": "Custom share link password", "passwordAutoGenerate": "Auto generate", "shareView": "Share view setting", "shareViewDes": "If selected, other users can see your view setting (layout, sorting, etc.) saved on the server server when accessing this shared folder.", diff --git a/public/locales/ja-JP/application.json b/public/locales/ja-JP/application.json index f598580..44a5d98 100644 --- a/public/locales/ja-JP/application.json +++ b/public/locales/ja-JP/application.json @@ -308,6 +308,7 @@ "createShareLink": "共有リンクの作成", "viewDetails": "詳細情報", "copy": "コピー", + "copyLinkAlongWithPassword": "パスワード付きリンクをコピー", "bytes": " ({{bytes}} バイト)", "storagePolicy": "ストレージポリシー", "childFolders": "ディレクトリの内容", @@ -470,7 +471,7 @@ "createShareLink": "共有リンク作成", "privateShare": "共有を非表示", "privateShareDes": "チェックを入れると他の人はあなたのプロフィールページでこの共有リンクを見ることができません。", - "passwordPrefix": "共有リンクパスワード:", + "useCustomPassword": "カスタムパスワードを使用", "passwordAutoGenerate": "自動生成", "expireAfterDownload": "ダウンロード後に自動的に期限切れ", "sharePassword": "共有パスワード", diff --git a/public/locales/zh-CN/application.json b/public/locales/zh-CN/application.json index 74a1534..e2619c1 100644 --- a/public/locales/zh-CN/application.json +++ b/public/locales/zh-CN/application.json @@ -307,6 +307,7 @@ "createShareLink": "创建分享链接", "viewDetails": "详细信息", "copy": "复制", + "copyLinkAlongWithPassword": "复制链接和密码", "bytes": " ({{bytes}} 字节)", "storagePolicy": "存储策略", "childFolders": "包含目录", @@ -469,7 +470,7 @@ "createShareLink": "创建分享链接", "privateShare": "隐藏分享", "privateShareDes": "勾选后,其他人无法在你的个人主页看到此分享链接。", - "passwordPrefix": "分享密码: ", + "useCustomPassword": "自定义分享密码", "passwordAutoGenerate": "自动生成", "expireAfterDownload": "下载后自动过期", "sharePassword": "分享密码", diff --git a/public/locales/zh-TW/application.json b/public/locales/zh-TW/application.json index 92d4824..b34171e 100644 --- a/public/locales/zh-TW/application.json +++ b/public/locales/zh-TW/application.json @@ -307,6 +307,7 @@ "createShareLink": "建立分享連結", "viewDetails": "詳細資訊", "copy": "復制", + "copyLinkAlongWithPassword": "復制連結和密碼", "bytes": " ({{bytes}} 位元組)", "storagePolicy": "儲存策略", "childFolders": "包含目錄", @@ -465,7 +466,7 @@ "createShareLink": "建立分享連結", "privateShare": "隱藏分享", "privateShareDes": "勾選後,其他人無法在你的個人主頁看到此分享連結。", - "passwordPrefix": "分享密碼:", + "useCustomPassword": "使用自定義密碼", "passwordAutoGenerate": "自動生成", "expireAfterDownload": "下載後自動過期", "sharePassword": "分享密碼", diff --git a/src/component/FileManager/Dialogs/Share/ShareDialog.tsx b/src/component/FileManager/Dialogs/Share/ShareDialog.tsx index ab2c8db..6e7a033 100644 --- a/src/component/FileManager/Dialogs/Share/ShareDialog.tsx +++ b/src/component/FileManager/Dialogs/Share/ShareDialog.tsx @@ -1,4 +1,4 @@ -import { Box, DialogContent, IconButton, Tooltip, useTheme } from "@mui/material"; +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"; @@ -15,6 +15,7 @@ import DraggableDialog from "../../../Dialogs/DraggableDialog.tsx"; import Share from "../../../Icons/Share.tsx"; import { FileManagerIndex } from "../../FileManager.tsx"; import ShareSettingContent, { downloadOptions, expireOptions, ShareSetting } from "./ShareSetting.tsx"; +import {CopyAll} from "@mui/icons-material"; const initialSetting: ShareSetting = { @@ -25,6 +26,8 @@ const initialSetting: ShareSetting = { const shareToSetting = (share: ShareModel, t: TFunction): ShareSetting => { const res: ShareSetting = { is_private: share.is_private, + password: share.password, + use_custom_password: true, share_view: share.share_view, downloads: share.remain_downloads != undefined && share.remain_downloads > 0, @@ -129,7 +132,7 @@ const ShareDialog = () => { maxWidth: "xs", }} cancelText={shareLink ? "common:close" : undefined} - okText={shareLink ? "fileManager.copy" : undefined} + okText={shareLink ? "fileManager.copyLinkAlongWithPassword" : undefined} secondaryAction={ shareLink ? // @ts-ignore @@ -161,15 +164,55 @@ const ShareDialog = () => { /> )} {shareLink && ( - e.target.select()} - /> + + e.target.select()} + slotProps={{ + input: { + endAdornment: ( + copyToClipboard(shareLink.substring(0, shareLink.lastIndexOf("/")))} + size="small" + sx={{ marginRight: -1 }} + > + + + ) + } + }} + /> + e.target.select()} + slotProps={{ + input: { + endAdornment: ( + copyToClipboard(setting.password ?? "")} + size="small" + sx={{ marginRight: -1 }} + > + + + ) + } + }} + /> + )} diff --git a/src/component/FileManager/Dialogs/Share/ShareSetting.tsx b/src/component/FileManager/Dialogs/Share/ShareSetting.tsx index 5d84e99..5e31607 100644 --- a/src/component/FileManager/Dialogs/Share/ShareSetting.tsx +++ b/src/component/FileManager/Dialogs/Share/ShareSetting.tsx @@ -71,6 +71,7 @@ const StyledListItemButton = styled(ListItemButton)(() => ({})); export interface ShareSetting { is_private?: boolean; + use_custom_password?: boolean; password?: string; share_view?: boolean; downloads?: boolean; @@ -154,25 +155,37 @@ const ShareSettingContent = ({ setting, file, editing, onSettingChange }: ShareS {t("application:modals.privateShareDes")} - {setting.is_private && ( + {setting.is_private && - {t("application:modals.passwordPrefix")} - - { - onSettingChange({ ...setting, password: e.target.value }); - }} - placeholder={t("application:modals.passwordAutoGenerate")} - fullWidth - /> - - - )} + {!editing && ( + { + onSettingChange({ ...setting, use_custom_password: !setting.use_custom_password }); + }} /> + )} + {!setting.use_custom_password && ( + {t("application:modals.useCustomPassword")} + )} + {setting.use_custom_password && ( + + { + const value = e.target.value.trim(); + if (!/^[a-zA-Z0-9]*$/.test(value) || value.length > 32) return; + onSettingChange({ ...setting, password: value }); + }} + placeholder={t("application:modals.passwordAutoGenerate")} + fullWidth + /> + + )} + } {file?.type == FileType.folder && (