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
31 commentsEnabled: boolean,
32 downloadEnabled: boolean,
39 this.uuid = video.uuid
40 this.category = video.category.id
41 this.licence = video.licence.id
42 this.language = video.language.id
43 this.description = video.description
44 this.name = video.name
45 this.tags = video.tags
46 this.nsfw = video.nsfw
47 this.commentsEnabled = video.commentsEnabled
48 this.downloadEnabled = video.downloadEnabled
49 this.waitTranscoding = video.waitTranscoding
50 this.channelId = video.channel.id
51 this.privacy = video.privacy.id
52 this.support = video.support
53 this.thumbnailUrl = video.thumbnailUrl
54 this.previewUrl = video.previewUrl
56 this.scheduleUpdate = video.scheduledUpdate
57 this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
61 patch (values: { [ id: string ]: string }) {
62 Object.keys(values).forEach((key) => {
63 this[ key ] = values[ key ]
66 // If schedule publication, the video is private and will be changed to public privacy
67 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
68 const updateAt = new Date(values['schedulePublicationAt'])
69 updateAt.setSeconds(0)
71 this.privacy = VideoPrivacy.PRIVATE
72 this.scheduleUpdate = {
73 updateAt: updateAt.toISOString(),
74 privacy: VideoPrivacy.PUBLIC
77 this.scheduleUpdate = null
80 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
81 if (this.originallyPublishedAt) {
82 const originallyPublishedAt = new Date(values['originallyPublishedAt'])
83 this.originallyPublishedAt = originallyPublishedAt.toISOString()
86 // Use the same file than the preview for the thumbnail
87 if (this.previewfile) {
88 this.thumbnailfile = this.previewfile
94 category: this.category,
95 licence: this.licence,
96 language: this.language,
97 description: this.description,
98 support: this.support,
102 commentsEnabled: this.commentsEnabled,
103 downloadEnabled: this.downloadEnabled,
104 waitTranscoding: this.waitTranscoding,
105 channelId: this.channelId,
106 privacy: this.privacy,
107 originallyPublishedAt: this.originallyPublishedAt
110 // Special case if we scheduled an update
111 if (this.scheduleUpdate) {
112 Object.assign(json, {
113 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
114 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())