47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import axios from 'axios';
|
|
|
|
// We don't use the apiClient with the backend proxy for vercel blob,
|
|
// because this goes to our own Next.js API route.
|
|
export const blobApiClient = axios.create({
|
|
baseURL: '/api',
|
|
timeout: 60000, // 60 seconds because file upload might take a while
|
|
});
|
|
|
|
export interface BlobModelData {
|
|
url: string;
|
|
downloadUrl: string;
|
|
pathname: string;
|
|
size: number;
|
|
uploadedAt: string;
|
|
}
|
|
|
|
export interface GetBlobModelResponse {
|
|
status: string;
|
|
data: BlobModelData | null;
|
|
message?: string;
|
|
}
|
|
|
|
export interface UploadBlobModelResponse {
|
|
status: string;
|
|
data: BlobModelData;
|
|
message?: string;
|
|
}
|
|
|
|
export const getActiveModel = async (): Promise<BlobModelData | null> => {
|
|
const response = await blobApiClient.get<GetBlobModelResponse>('/blob-model');
|
|
return response.data.data;
|
|
};
|
|
|
|
export const uploadModel = async (file: File): Promise<BlobModelData> => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
const response = await blobApiClient.post<UploadBlobModelResponse>('/blob-model', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
});
|
|
|
|
return response.data.data;
|
|
};
|