This commit is contained in:
marzban-dev
2025-01-06 19:26:16 +03:30
parent 73d68810be
commit cdc0ebec26
13 changed files with 536 additions and 0 deletions
@@ -0,0 +1,45 @@
// imports
import { useMutation } from "@tanstack/vue-query";
import axios from "~/configs/axios.config";
import { API_ENDPOINTS } from "~/constants";
// types
export type AddDocRequest = {
name: string,
parent?: string,
branch: string | undefined,
type: {
title: "File" | "Folder",
icon: "bi:folder" | "bi:file-earmark"
},
content: File | undefined
};
// methods
export const handleAddDoc = async (variables: AddDocRequest & { updateUploadProgress: (p: number) => void }) => {
const { data } = await axios.post<AddDocRequest>(`${API_ENDPOINTS.branch.getDoc}/`, {
...variables,
type: variables.type.title.toLocaleLowerCase()
}, {
onUploadProgress: (progressEvent) => {
variables.updateUploadProgress(progressEvent.progress!);
},
headers: {
"Content-Type": "multipart/form-data"
}
});
return data;
};
// composable
const useAddDoc = () => {
return useMutation({
mutationFn: (variables: AddDocRequest & { updateUploadProgress: (p: number) => void }) => handleAddDoc(variables)
});
};
export default useAddDoc;