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
29 originallyPublishedAt?: Date | string
34 commentsEnabled: boolean,
35 downloadEnabled: boolean,
42 this.uuid = video.uuid
43 this.category = video.category.id
44 this.licence = video.licence.id
45 this.language = video.language.id
46 this.description = video.description
47 this.name = video.name
48 this.tags = video.tags
49 this.nsfw = video.nsfw
50 this.commentsEnabled = video.commentsEnabled
51 this.downloadEnabled = video.downloadEnabled
52 this.waitTranscoding = video.waitTranscoding
53 this.channelId = video.channel.id
54 this.privacy = video.privacy.id
55 this.support = video.support
56 this.thumbnailUrl = video.thumbnailUrl
57 this.previewUrl = video.previewUrl
59 this.scheduleUpdate = video.scheduledUpdate
60 this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
64 patch (values: { [ id: string ]: string }) {
65 Object.keys(values).forEach((key) => {
66 this[ key ] = values[ key ]
69 // If schedule publication, the video is private and will be changed to public privacy
70 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
71 const updateAt = new Date(values['schedulePublicationAt'])
72 updateAt.setSeconds(0)
74 this.privacy = VideoPrivacy.PRIVATE
75 this.scheduleUpdate = {
76 updateAt: updateAt.toISOString(),
77 privacy: VideoPrivacy.PUBLIC
80 this.scheduleUpdate = null
83 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
84 if (this.originallyPublishedAt) {
85 const originallyPublishedAt = new Date(values['originallyPublishedAt'])
86 this.originallyPublishedAt = originallyPublishedAt.toISOString()
89 // Use the same file than the preview for the thumbnail
90 if (this.previewfile) {
91 this.thumbnailfile = this.previewfile
97 category: this.category,
98 licence: this.licence,
99 language: this.language,
100 description: this.description,
101 support: this.support,
105 commentsEnabled: this.commentsEnabled,
106 downloadEnabled: this.downloadEnabled,
107 waitTranscoding: this.waitTranscoding,
108 channelId: this.channelId,
109 privacy: this.privacy,
110 originallyPublishedAt: this.originallyPublishedAt
113 // Special case if we scheduled an update
114 if (this.scheduleUpdate) {
115 Object.assign(json, {
116 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
117 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())