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
23 scheduleUpdate?: VideoScheduleUpdate
24 originallyPublishedAt?: Date | string
35 commentsEnabled: boolean
36 downloadEnabled: boolean
43 this.uuid = video.uuid
44 this.shortUUID = video.shortUUID
45 this.category = video.category.id
46 this.licence = video.licence.id
47 this.language = video.language.id
48 this.description = video.description
49 this.name = video.name
50 this.tags = video.tags
51 this.nsfw = video.nsfw
52 this.commentsEnabled = video.commentsEnabled
53 this.downloadEnabled = video.downloadEnabled
54 this.waitTranscoding = video.waitTranscoding
55 this.channelId = video.channel.id
56 this.privacy = video.privacy.id
57 this.support = video.support
58 this.thumbnailUrl = video.thumbnailUrl
59 this.previewUrl = video.previewUrl
61 this.scheduleUpdate = video.scheduledUpdate
62 this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
64 this.pluginData = video.pluginData
68 patch (values: { [ id: string ]: any }) {
69 Object.keys(values).forEach((key) => {
70 this[key] = values[key]
73 // If schedule publication, the video is private and will be changed to public privacy
74 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
75 const updateAt = new Date(values['schedulePublicationAt'])
76 updateAt.setSeconds(0)
78 this.privacy = VideoPrivacy.PRIVATE
79 this.scheduleUpdate = {
80 updateAt: updateAt.toISOString(),
81 privacy: VideoPrivacy.PUBLIC
84 this.scheduleUpdate = null
87 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
88 if (this.originallyPublishedAt) {
89 const originallyPublishedAt = new Date(values['originallyPublishedAt'])
90 this.originallyPublishedAt = originallyPublishedAt.toISOString()
93 // Use the same file than the preview for the thumbnail
94 if (this.previewfile) {
95 this.thumbnailfile = this.previewfile
101 category: this.category,
102 licence: this.licence,
103 language: this.language,
104 description: this.description,
105 support: this.support,
109 commentsEnabled: this.commentsEnabled,
110 downloadEnabled: this.downloadEnabled,
111 waitTranscoding: this.waitTranscoding,
112 channelId: this.channelId,
113 privacy: this.privacy,
114 originallyPublishedAt: this.originallyPublishedAt
117 // Special case if we scheduled an update
118 if (this.scheduleUpdate) {
119 Object.assign(json, {
120 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
121 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())