You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.9 KiB
TypeScript
41 lines
1.9 KiB
TypeScript
import $api from '@/http';
|
|
import { AxiosResponse } from 'axios';
|
|
import { VideoResponse, VideosResponse } from '@/models/response/VideoResponse';
|
|
import { IVideoReq } from '@/models/IVideo';
|
|
|
|
export default class VideoService {
|
|
|
|
static async Create({ name, videoHQ, videoLQ, playlist, artist }: IVideoReq, setUploadProgress: (value: number) => void): Promise<AxiosResponse<VideoResponse>> {
|
|
|
|
const formData = new FormData();
|
|
formData.append("name", name);
|
|
videoHQ && formData.append("videoHQ", videoHQ[0]);
|
|
videoLQ && formData.append("videoLQ", videoLQ[0]);
|
|
formData.append("playlist", playlist ?? '');
|
|
formData.append("artist", artist);
|
|
|
|
return $api.post<VideoResponse>('/video', formData, {
|
|
withCredentials: true,
|
|
onUploadProgress: function(progressEvent) {
|
|
if(progressEvent.total) {
|
|
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
|
setUploadProgress(percentCompleted);
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
static async GetAll({ page, search }: {page?: number, search?: string}): Promise<AxiosResponse<VideosResponse>> {
|
|
return $api.get<VideosResponse>('/video', {withCredentials: true, params: {page, search}})
|
|
}
|
|
static async GetOne(): Promise<AxiosResponse<VideoResponse>> {
|
|
return $api.get<VideoResponse>('/video/random', {withCredentials: true});
|
|
}
|
|
static async Edit(_id: string, { name, videoHQ, videoLQ, playlist, artist }: IVideoReq): Promise<AxiosResponse<VideoResponse>> {
|
|
return $api.put<VideoResponse>('/video/'+_id, {name, videoHQ, videoLQ, playlist, artist}, {withCredentials: true})
|
|
}
|
|
|
|
static async Delete(_id: string): Promise<AxiosResponse<VideoResponse>> {
|
|
return $api.delete<VideoResponse>('/video/'+_id, {withCredentials: true})
|
|
}
|
|
} |