1 import { Video, VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
3 export class VideoEdit implements VideoUpdate {
4 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
13 commentsEnabled: boolean
14 downloadEnabled: boolean
15 waitTranscoding: boolean
25 scheduleUpdate?: VideoScheduleUpdate
26 originallyPublishedAt?: Date | string
33 commentsEnabled: boolean,
34 downloadEnabled: boolean,
41 this.uuid = video.uuid
42 this.category = video.category.id
43 this.licence = video.licence.id
44 this.language = video.language.id
45 this.description = video.description
46 this.name = video.name
47 this.tags = video.tags
48 this.nsfw = video.nsfw
49 this.commentsEnabled = video.commentsEnabled
50 this.downloadEnabled = video.downloadEnabled
51 this.waitTranscoding = video.waitTranscoding
52 this.channelId = video.channel.id
53 this.privacy = video.privacy.id
54 this.support = video.support
55 this.thumbnailUrl = video.thumbnailUrl
56 this.previewUrl = video.previewUrl
58 this.scheduleUpdate = video.scheduledUpdate
59 this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
61 this.pluginData = video.pluginData
65 patch (values: { [ id: string ]: any }) {
66 Object.keys(values).forEach((key) => {
67 this[ key ] = values[ key ]
70 // If schedule publication, the video is private and will be changed to public privacy
71 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
72 const updateAt = new Date(values['schedulePublicationAt'])
73 updateAt.setSeconds(0)
75 this.privacy = VideoPrivacy.PRIVATE
76 this.scheduleUpdate = {
77 updateAt: updateAt.toISOString(),
78 privacy: VideoPrivacy.PUBLIC
81 this.scheduleUpdate = null
84 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
85 if (this.originallyPublishedAt) {
86 const originallyPublishedAt = new Date(values['originallyPublishedAt'])
87 this.originallyPublishedAt = originallyPublishedAt.toISOString()
90 // Use the same file than the preview for the thumbnail
91 if (this.previewfile) {
92 this.thumbnailfile = this.previewfile
98 category: this.category,
99 licence: this.licence,
100 language: this.language,
101 description: this.description,
102 support: this.support,
106 commentsEnabled: this.commentsEnabled,
107 downloadEnabled: this.downloadEnabled,
108 waitTranscoding: this.waitTranscoding,
109 channelId: this.channelId,
110 privacy: this.privacy,
111 originallyPublishedAt: this.originallyPublishedAt
114 // Special case if we scheduled an update
115 if (this.scheduleUpdate) {
116 Object.assign(json, {
117 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
118 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())