feat: add recursive remove directory option

This commit is contained in:
2024-08-21 07:34:10 +07:00
parent 7532c6330c
commit 145bf3f1a9
3 changed files with 66 additions and 6 deletions
+5 -2
View File
@@ -40,10 +40,13 @@ export const usePutObject = (
export const useDeleteObject = (
bucket: string,
options?: UseMutationOptions<any, Error, string>
options?: UseMutationOptions<any, Error, { key: string; recursive?: boolean }>
) => {
return useMutation({
mutationFn: (key) => api.delete(`/browse/${bucket}/${key}`),
mutationFn: (data) =>
api.delete(`/browse/${bucket}/${data.key}`, {
params: { recursive: data.recursive },
}),
...options,
});
};
@@ -34,8 +34,17 @@ const ObjectActions = ({ prefix = "", object, end }: Props) => {
};
const onDelete = () => {
if (window.confirm("Are you sure you want to delete this object?")) {
deleteObject.mutate(prefix + object.objectKey);
if (
window.confirm(
`Are you sure you want to delete this ${
isDirectory ? "directory and its content" : "object"
}?`
)
) {
deleteObject.mutate({
key: prefix + object.objectKey,
recursive: isDirectory,
});
}
};