videos.ts54 lines, 1.4 KB
| 1 | import { apiClient } from "./client"; |
| 2 | import { |
| 3 | ApiResponse, |
| 4 | JobsListResponse, |
| 5 | JobStatus, |
| 6 | Video, |
| 7 | VideoSubmissionRequest, |
| 8 | VideoSubmissionResponse, |
| 9 | } from "./types"; |
| 10 | |
| 11 | export const submitVideo = async ( |
| 12 | data: VideoSubmissionRequest |
| 13 | ): Promise<VideoSubmissionResponse> => { |
| 14 | const response = await apiClient.post<ApiResponse<VideoSubmissionResponse>>( |
| 15 | "/videos/transcribe", |
| 16 | data |
| 17 | ); |
| 18 | return response.data.data; |
| 19 | }; |
| 20 | |
| 21 | export const getJobStatus = async (jobId: string): Promise<JobStatus> => { |
| 22 | const response = await apiClient.get<ApiResponse<JobStatus>>( |
| 23 | `/videos/transcribe/${jobId}/status` |
| 24 | ); |
| 25 | console.log(response.data.data); |
| 26 | return response.data.data; |
| 27 | }; |
| 28 | |
| 29 | export const getAllJobs = async (): Promise<JobsListResponse> => { |
| 30 | const response = await apiClient.get<ApiResponse<JobStatus[]>>( |
| 31 | "/videos/jobs" |
| 32 | ); |
| 33 | return { jobs: response.data.data }; |
| 34 | }; |
| 35 | |
| 36 | export const getUserVideos = async (): Promise<Video[]> => { |
| 37 | const response = await apiClient.get<ApiResponse<Video[]>>("/videos"); |
| 38 | return response.data.data; |
| 39 | }; |
| 40 | |
| 41 | export const getVideoById = async (videoId: string): Promise<Video> => { |
| 42 | const response = await apiClient.get<ApiResponse<Video>>( |
| 43 | `/videos/${videoId}` |
| 44 | ); |
| 45 | |
| 46 | return response.data.data; |
| 47 | }; |
| 48 | |
| 49 | export async function cancelJob(jobId: string): Promise<{ message: string }> { |
| 50 | const { data } = await apiClient.post<ApiResponse<{ message: string }>>( |
| 51 | `/videos/jobs/${jobId}/cancel` |
| 52 | ); |
| 53 | return data.data; |
| 54 | } |