1 import { VideoPrivacy } from '../../../../../shared/models/videos/video-privacy.enum'
2 import { VideoUpdate } from '../../../../../shared/models/videos'
3 import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
4 import { Video } from '../../../../../shared/models/videos/video.model'
6 export class VideoEdit implements VideoUpdate {
7 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
16 commentsEnabled: boolean
17 downloadEnabled: boolean
18 waitTranscoding: boolean
28 scheduleUpdate?: VideoScheduleUpdate
30 constructor (video?: Video & { tags: string[], commentsEnabled: boolean, downloadEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) {
33 this.uuid = video.uuid
34 this.category = video.category.id
35 this.licence = video.licence.id
36 this.language = video.language.id
37 this.description = video.description
38 this.name = video.name
39 this.tags = video.tags
40 this.nsfw = video.nsfw
41 this.commentsEnabled = video.commentsEnabled
42 this.downloadEnabled = video.downloadEnabled
43 this.waitTranscoding = video.waitTranscoding
44 this.channelId = video.channel.id
45 this.privacy = video.privacy.id
46 this.support = video.support
47 this.thumbnailUrl = video.thumbnailUrl
48 this.previewUrl = video.previewUrl
50 this.scheduleUpdate = video.scheduledUpdate
54 patch (values: Object) {
55 Object.keys(values).forEach((key) => {
56 this[ key ] = values[ key ]
59 // If schedule publication, the video is private and will be changed to public privacy
60 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
61 const updateAt = (values['schedulePublicationAt'] as Date)
62 updateAt.setSeconds(0)
64 this.privacy = VideoPrivacy.PRIVATE
65 this.scheduleUpdate = {
66 updateAt: updateAt.toISOString(),
67 privacy: VideoPrivacy.PUBLIC
70 this.scheduleUpdate = null
76 category: this.category,
77 licence: this.licence,
78 language: this.language,
79 description: this.description,
80 support: this.support,
84 commentsEnabled: this.commentsEnabled,
85 downloadEnabled: this.downloadEnabled,
86 waitTranscoding: this.waitTranscoding,
87 channelId: this.channelId,
91 // Special case if we scheduled an update
92 if (this.scheduleUpdate) {
94 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
95 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())