mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-06 02:00:46 +00:00
- Finished UI and functionality for Pagination - Pagination implemented in audio library - Finished UI for uploading audio - Connected the UI to the upload media endpoint - Audio Library auto-refreshes upon finishing upload - Fixed up audio upload bugs that already existed in V2V workflow Co-authored-by: wil <wil@storyteller.ai>
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { uploadAudioV2V } from "~/api";
|
|
|
|
export interface UploadAudioRequest {
|
|
uuid_idempotency_token: string,
|
|
source?: string, // eg. "device", "file"
|
|
file: any,
|
|
}
|
|
|
|
export interface UploadAudioResponse {
|
|
success: boolean,
|
|
upload_token?: string,
|
|
}
|
|
|
|
export function UploadAudioIsOk(response: UploadAudioResponse) {
|
|
return response?.success === true;
|
|
}
|
|
|
|
export async function UploadAudio(request: UploadAudioRequest, sessionToken:string) : Promise<UploadAudioResponse>
|
|
{
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('uuid_idempotency_token', request.uuid_idempotency_token);
|
|
formData.append('file', request.file);
|
|
|
|
if (request.source !== undefined) {
|
|
formData.append('source', request.source);
|
|
}
|
|
|
|
return fetch(uploadAudioV2V, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'session': sessionToken,
|
|
},
|
|
body: formData,
|
|
})
|
|
.then(res => res.json())
|
|
.then(res => {
|
|
if (res && 'success' in res) {
|
|
return res;
|
|
} else {
|
|
return { success : false };
|
|
}
|
|
})
|
|
.catch(e => {
|
|
return { success : false };
|
|
});
|
|
} |