mirror of
https://github.com/coaidev/coai.git
synced 2025-06-02 03:40:18 +09:00
37 lines
682 B
TypeScript
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;
|
|
}
|