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 waitTranscoding: boolean
27 scheduleUpdate?: VideoScheduleUpdate
29 constructor (video?: Video & { tags: string[], commentsEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) {
32 this.uuid = video.uuid
33 this.category = video.category.id
34 this.licence = video.licence.id
35 this.language = video.language.id
36 this.description = video.description
37 this.name = video.name
38 this.tags = video.tags
39 this.nsfw = video.nsfw
40 this.commentsEnabled = video.commentsEnabled
41 this.waitTranscoding = video.waitTranscoding
42 this.channelId = video.channel.id
43 this.privacy = video.privacy.id
44 this.support = video.support
45 this.thumbnailUrl = video.thumbnailUrl
46 this.previewUrl = video.previewUrl
48 this.scheduleUpdate = video.scheduledUpdate
52 patch (values: Object) {
53 Object.keys(values).forEach((key) => {
54 this[ key ] = values[ key ]
57 // If schedule publication, the video is private and will be changed to public privacy
58 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
59 const updateAt = (values['schedulePublicationAt'] as Date)
60 updateAt.setSeconds(0)
62 this.privacy = VideoPrivacy.PRIVATE
63 this.scheduleUpdate = {
64 updateAt: updateAt.toISOString(),
65 privacy: VideoPrivacy.PUBLIC
68 this.scheduleUpdate = null
74 category: this.category,
75 licence: this.licence,
76 language: this.language,
77 description: this.description,
78 support: this.support,
82 commentsEnabled: this.commentsEnabled,
83 waitTranscoding: this.waitTranscoding,
84 channelId: this.channelId,
88 // Special case if we scheduled an update
89 if (this.scheduleUpdate) {
91 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
92 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())