From 245cc5ae538b074a545b84b213bef17a262cf4cb Mon Sep 17 00:00:00 2001 From: jenken827 Date: Wed, 20 Aug 2025 13:04:48 +0800 Subject: [PATCH] refactor:batch rename and remove --- src/pages/home/toolbar/BatchRename.tsx | 2 +- src/pages/home/toolbar/Delete.tsx | 5 ++++- src/types/obj.ts | 6 ++++++ src/utils/api.ts | 13 +++++++++++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pages/home/toolbar/BatchRename.tsx b/src/pages/home/toolbar/BatchRename.tsx index c5d23e129..2986497e3 100644 --- a/src/pages/home/toolbar/BatchRename.tsx +++ b/src/pages/home/toolbar/BatchRename.tsx @@ -143,7 +143,7 @@ export const BatchRename = () => { const renameObj: RenameObj = { src_name: obj.name, - new_name: srcName() + tempNum + "." + suffix, + new_name: srcName() + tempNum + (suffix == "" ? "" : "." + suffix), } tempNum = (parseInt(tempNum) + 1) .toString() diff --git a/src/pages/home/toolbar/Delete.tsx b/src/pages/home/toolbar/Delete.tsx index 6666dca08..75c1c6ba4 100644 --- a/src/pages/home/toolbar/Delete.tsx +++ b/src/pages/home/toolbar/Delete.tsx @@ -54,7 +54,10 @@ export const Delete = () => { onClick={async () => { const resp = await ok( pathname(), - selectedObjs().map((obj) => obj.name), + selectedObjs().map((obj) => ({ + id: obj.id, + name: obj.name, + })), ) handleRespWithNotifySuccess(resp, () => { refresh() diff --git a/src/types/obj.ts b/src/types/obj.ts index 0c64731e1..fae9454e4 100644 --- a/src/types/obj.ts +++ b/src/types/obj.ts @@ -9,6 +9,7 @@ export enum ObjType { } export interface Obj { + id: string name: string size: number is_dir: boolean @@ -24,6 +25,11 @@ export type StoreObj = Obj & { selected?: boolean } +export type IDName = { + id: string + name: string +} + export type RenameObj = { src_name: string new_name: string diff --git a/src/utils/api.ts b/src/utils/api.ts index f22415076..a9234d85f 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -9,6 +9,7 @@ import { RenameObj, ArchiveMeta, ArchiveList, + IDName, } from "~/types" import { r } from "." @@ -104,8 +105,16 @@ export const fsCopy = ( return r.post("/fs/copy", { src_dir, dst_dir, names, overwrite }) } -export const fsRemove = (dir: string, names: string[]): PEmptyResp => { - return r.post("/fs/remove", { dir, names }) +export const fsRemove = (dir: string, names: IDName[]): PEmptyResp => { + return r.post( + "/fs/remove", + { names }, + { + headers: { + "File-Path": encodeURIComponent(dir), + }, + }, + ) } export const fsRemoveEmptyDirectory = (src_dir: string): PEmptyResp => {