import { ResultList } from '../../../../../shared/models/result-list.model'
import { UserVideoRateUpdate } from '../../../../../shared/models/videos/user-video-rate-update.model'
import { UserVideoRate } from '../../../../../shared/models/videos/user-video-rate.model'
+import { VideoFilter } from '../../../../../shared/models/videos/video-query.type'
import { VideoRateType } from '../../../../../shared/models/videos/video-rate.type'
import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model'
import { environment } from '../../../environments/environment'
import { VideoDetails } from './video-details.model'
import { VideoEdit } from './video-edit.model'
import { Video } from './video.model'
+import { objectToFormData } from '@app/shared/misc/utils'
@Injectable()
export class VideoService {
private restService: RestService
) {}
+ getVideoViewUrl (uuid: string) {
+ return VideoService.BASE_VIDEO_URL + uuid + '/views'
+ }
+
getVideo (uuid: string): Observable<VideoDetails> {
return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
.map(videoHash => new VideoDetails(videoHash))
}
viewVideo (uuid: string): Observable<VideoDetails> {
- return this.authHttp.post(VideoService.BASE_VIDEO_URL + uuid + '/views', {})
+ return this.authHttp.post(this.getVideoViewUrl(uuid), {})
.map(this.restExtractor.extractDataBool)
.catch(this.restExtractor.handleError)
}
const licence = video.licence || undefined
const category = video.category || undefined
const description = video.description || undefined
+ const support = video.support || undefined
const body: VideoUpdate = {
name: video.name,
category,
licence,
language,
+ support,
description,
privacy: video.privacy,
tags: video.tags,
- nsfw: video.nsfw
+ nsfw: video.nsfw,
+ commentsEnabled: video.commentsEnabled,
+ thumbnailfile: video.thumbnailfile,
+ previewfile: video.previewfile
}
- return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, body)
+ const data = objectToFormData(body)
+
+ return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, data)
.map(this.restExtractor.extractDataBool)
.catch(this.restExtractor.handleError)
}
.catch((res) => this.restExtractor.handleError(res))
}
- getVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+ getVideos (
+ videoPagination: ComponentPagination,
+ sort: SortField,
+ filter?: VideoFilter
+ ): Observable<{ videos: Video[], totalVideos: number}> {
const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
+ if (filter) {
+ params = params.set('filter', filter)
+ }
+
return this.authHttp
.get(VideoService.BASE_VIDEO_URL, { params })
.map(this.extractVideos)
return this.setVideoRate(id, 'dislike')
}
+ unsetVideoLike (id: number) {
+ return this.setVideoRate(id, 'none')
+ }
+
getUserVideoRating (id: number): Observable<UserVideoRate> {
const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating'