coai/app/src/conversation/file.ts
2023-11-09 18:38:53 +08:00

37 lines
682 B
TypeScript

import axios from "axios";
import { blob_api } from "@/conf.ts";
export type BlobParserResponse = {
status: number;
content: string;
error?: string;
};
export type FileObject = {
name: string;
content: string;
size?: number;
};
export type FileArray = FileObject[];
export async function blobParser(file: File): Promise<BlobParserResponse> {
const resp = await axios.post(
`${blob_api}/upload`,
{ file },
{
headers: { "Content-Type": "multipart/form-data" },
},
);
if (resp.status !== 200) {
return {
status: resp.status,
content: "",
error: resp.statusText,
};
}
return resp.data as BlobParserResponse;
}