Adekabang 33ed173dec feat: align API endpoints with official specifications for bucket and key management
- Updated HTTP methods for bucket and key operations to align with the official Garage Admin API v2 specifications, changing DELETE methods to POST where necessary.
- Modified frontend hooks and documentation to reflect these changes, ensuring consistency across the application.
- Completed tasks for verifying and aligning delete operations and reviewing other HTTP methods.
2025-07-31 18:10:39 -04:00

39 lines
870 B
TypeScript

import api from "@/lib/api";
import {
useMutation,
UseMutationOptions,
useQuery,
} from "@tanstack/react-query";
import { Key } from "./types";
import { CreateKeySchema } from "./schema";
export const useKeys = () => {
return useQuery({
queryKey: ["keys"],
queryFn: () => api.get<Key[]>("/v2/ListKeys"),
});
};
export const useCreateKey = (
options?: UseMutationOptions<unknown, Error, CreateKeySchema>
) => {
return useMutation({
mutationFn: async (body) => {
if (body.isImport) {
return api.post("/v2/ImportKey", { body });
}
return api.post("/v2/CreateKey", { body });
},
...options,
});
};
export const useRemoveKey = (
options?: UseMutationOptions<unknown, Error, string>
) => {
return useMutation({
mutationFn: (id) => api.post("/v2/DeleteKey", { params: { id } }),
...options,
});
};