From 07a13c973cd1875f4360981bea801cfd20f5caf2 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Thu, 24 Apr 2025 15:18:45 +0800 Subject: [PATCH] fix:(share): cannot edit single file share link (https://github.com/cloudreve/Cloudreve/issues/2293) --- src/component/Pages/Shares/ShareCard.tsx | 2 +- src/redux/thunks/share.ts | 32 ++++++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/component/Pages/Shares/ShareCard.tsx b/src/component/Pages/Shares/ShareCard.tsx index bee64b9..dc09b9c 100644 --- a/src/component/Pages/Shares/ShareCard.tsx +++ b/src/component/Pages/Shares/ShareCard.tsx @@ -68,7 +68,7 @@ const ActionMenu = ({ share, onShareDeleted, onClose, ...rest }: ActionMenuProps }, [t, share.id, onClose, dispatch, enqueueSnackbar]); const openEdit = useCallback(() => { - dispatch(openShareEditByID(share.id, share.password)); + dispatch(openShareEditByID(share.id, share.password, share.source_type == FileType.file)); onClose && onClose({}, "backdropClick"); }, [dispatch, share, onClose]); diff --git a/src/redux/thunks/share.ts b/src/redux/thunks/share.ts index 9f6fe57..25becb9 100644 --- a/src/redux/thunks/share.ts +++ b/src/redux/thunks/share.ts @@ -1,14 +1,14 @@ -import { FileResponse, Share, ShareCreateService } from "../../api/explorer.ts"; -import { AppThunk } from "../store.ts"; -import { ShareSetting } from "../../component/FileManager/Dialogs/Share/ShareSetting.tsx"; -import { getFileInfo, getShareInfo, sendCreateShare, sendUpdateShare } from "../../api/api.ts"; -import { fileUpdated } from "../fileManagerSlice.ts"; -import CrUri from "../../util/uri.ts"; -import { addShareInfo, setManageShareDialog, setShareLinkDialog } from "../globalStateSlice.ts"; -import { longRunningTaskWithSnackbar } from "./file.ts"; -import { enqueueSnackbar } from "notistack"; -import { DefaultCloseAction } from "../../component/Common/Snackbar/snackbar.tsx"; import i18next from "i18next"; +import { enqueueSnackbar } from "notistack"; +import { getFileInfo, getFileList, getShareInfo, sendCreateShare, sendUpdateShare } from "../../api/api.ts"; +import { FileResponse, Share, ShareCreateService } from "../../api/explorer.ts"; +import { DefaultCloseAction } from "../../component/Common/Snackbar/snackbar.tsx"; +import { ShareSetting } from "../../component/FileManager/Dialogs/Share/ShareSetting.tsx"; +import CrUri from "../../util/uri.ts"; +import { fileUpdated } from "../fileManagerSlice.ts"; +import { addShareInfo, setManageShareDialog, setShareLinkDialog } from "../globalStateSlice.ts"; +import { AppThunk } from "../store.ts"; +import { longRunningTaskWithSnackbar } from "./file.ts"; export function createOrUpdateShareLink( index: number, @@ -104,11 +104,11 @@ export function queueLoadShareInfo(uri: CrUri, countViews: boolean = false): App }; } -export function openShareEditByID(shareId: string, password?: string): AppThunk { +export function openShareEditByID(shareId: string, password?: string, singleFile?: boolean): AppThunk { return async (dispatch) => { try { const { share, file } = await longRunningTaskWithSnackbar( - dispatch(getFileAndShareById(shareId, password)), + dispatch(getFileAndShareById(shareId, password, singleFile)), "application:uploader.processing", ); dispatch( @@ -128,6 +128,7 @@ export function openShareEditByID(shareId: string, password?: string): AppThunk function getFileAndShareById( shareId: string, password?: string, + singleFile?: boolean, ): AppThunk< Promise<{ share: Share; @@ -147,7 +148,12 @@ function getFileAndShareById( throw e; } - const file = await dispatch(getFileInfo({ uri: share.source_uri ?? "" })); + let file: FileResponse | undefined = undefined; + if (singleFile) { + file = (await dispatch(getFileList({ uri: share.source_uri ?? "", page_size: 50 })))?.files[0]; + } else { + file = await dispatch(getFileInfo({ uri: share.source_uri ?? "" })); + } return { share, file }; }; }