quivr/frontend/lib/api/upload/upload.ts
2023-09-08 11:03:14 +02:00

27 lines
680 B
TypeScript

import { AxiosInstance } from "axios";
import { UUID } from "crypto";
import { ToastData } from "@/lib/components/ui/Toast/domain/types";
export type UploadResponse = {
data: { type: ToastData["variant"]; message: ToastData["text"] };
};
export type UploadInputProps = {
brainId: UUID;
formData: FormData;
chat_id?: UUID;
};
export const uploadFile = async (
props: UploadInputProps,
axiosInstance: AxiosInstance
): Promise<UploadResponse> => {
let uploadUrl = `/upload?brain_id=${props.brainId}`;
if (props.chat_id !== undefined) {
uploadUrl = uploadUrl.concat(`&chat_id=${props.chat_id}`);
}
return axiosInstance.post(uploadUrl, props.formData);
};