fix: envkey upload timeout

This commit is contained in:
Daniel Hougaard
2024-10-14 11:49:26 +04:00
parent 7fdcb29bab
commit 2dc1416f30
5 changed files with 94 additions and 73 deletions
+21 -14
View File
@@ -8,20 +8,27 @@ export const useImportEnvKey = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
encryptedJson,
decryptionKey
}: {
encryptedJson: {
nonce: string;
data: string;
};
decryptionKey: string;
}) => {
await apiRequest.post("/api/v3/migrate/env-key/", {
encryptedJson,
decryptionKey
});
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/migrate/env-key/", formData, {
headers: {
"Content-Type": "multipart/form-data"
},
onUploadProgress: (progressEvent) => {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
console.log(`Upload Progress: ${percentCompleted}%`);
}
});
console.log("Upload successful:", response.data);
} catch (error) {
console.error("Upload failed:", error);
}
},
onSuccess: () => {
queryClient.invalidateQueries(workspaceKeys.getAllUserWorkspace);