feat: add bucket browser

This commit is contained in:
2024-08-19 02:28:25 +07:00
parent 934e0c409c
commit 93a1dce5f7
35 changed files with 770 additions and 137 deletions
+37 -2
View File
@@ -1,6 +1,14 @@
import api from "@/lib/api";
import { useQuery } from "@tanstack/react-query";
import { GetObjectsResult, UseBrowserObjectOptions } from "./types";
import {
useMutation,
UseMutationOptions,
useQuery,
} from "@tanstack/react-query";
import {
GetObjectsResult,
PutObjectPayload,
UseBrowserObjectOptions,
} from "./types";
export const useBrowseObjects = (
bucket: string,
@@ -12,3 +20,30 @@ export const useBrowseObjects = (
api.get<GetObjectsResult>(`/browse/${bucket}`, { params: options }),
});
};
export const usePutObject = (
bucket: string,
options?: UseMutationOptions<any, Error, PutObjectPayload>
) => {
return useMutation({
mutationFn: async (body) => {
const formData = new FormData();
if (body.file) {
formData.append("file", body.file);
}
return api.put(`/browse/${bucket}/${body.key}`, { body: formData });
},
...options,
});
};
export const useDeleteObject = (
bucket: string,
options?: UseMutationOptions<any, Error, string>
) => {
return useMutation({
mutationFn: (key) => api.delete(`/browse/${bucket}/${key}`),
...options,
});
};