mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 07:29:35 +00:00
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { apiRequest } from "@app/config/request";
|
|
|
|
import { projectKeys } from "../projects";
|
|
|
|
export const useImportEnvKey = () => {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ file, decryptionKey }: { file: File; decryptionKey: string }) => {
|
|
const formData = new FormData();
|
|
|
|
formData.append("decryptionKey", decryptionKey);
|
|
formData.append("file", file);
|
|
|
|
try {
|
|
const response = await apiRequest.post("/api/v3/external-migration/env-key/", formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data"
|
|
},
|
|
onUploadProgress: (progressEvent) => {
|
|
const percentCompleted = Math.round(
|
|
(progressEvent.loaded * 100) / (progressEvent?.total || 1)
|
|
);
|
|
console.log(`Upload Progress: ${percentCompleted}%`);
|
|
}
|
|
});
|
|
|
|
console.log("Upload successful:", response.data);
|
|
} catch (error) {
|
|
console.error("Upload failed:", error);
|
|
}
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: projectKeys.getAllUserProjects()
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
export const useImportVault = () => {
|
|
return useMutation({
|
|
mutationFn: async ({
|
|
vaultAccessToken,
|
|
vaultNamespace,
|
|
vaultUrl,
|
|
mappingType,
|
|
gatewayId
|
|
}: {
|
|
vaultAccessToken: string;
|
|
vaultNamespace?: string;
|
|
vaultUrl: string;
|
|
mappingType: string;
|
|
gatewayId?: string;
|
|
}) => {
|
|
await apiRequest.post("/api/v3/external-migration/vault/", {
|
|
vaultAccessToken,
|
|
vaultNamespace,
|
|
vaultUrl,
|
|
mappingType,
|
|
gatewayId
|
|
});
|
|
}
|
|
});
|
|
};
|