mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-18 10:23:21 +07:00
feat: add bucket browser
This commit is contained in:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user