1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
3 import { VideoDetails } from './video-details.model'
5 export class VideoEdit implements VideoUpdate {
6 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
15 commentsEnabled: boolean
16 downloadEnabled: boolean
17 waitTranscoding: boolean
25 scheduleUpdate?: VideoScheduleUpdate
26 originallyPublishedAt?: Date | string
34 constructor (video?: VideoDetails) {
38 this.uuid = video.uuid
39 this.shortUUID = video.shortUUID
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.waitTranscoding = video.waitTranscoding
48 this.channelId = video.channel.id
49 this.privacy = video.privacy.id
51 this.support = video.support
53 this.commentsEnabled = video.commentsEnabled
54 this.downloadEnabled = video.downloadEnabled
56 if (video.thumbnailPath) this.thumbnailUrl = getAbsoluteAPIUrl() + video.thumbnailPath
57 if (video.previewPath) this.previewUrl = getAbsoluteAPIUrl() + video.previewPath
59 this.scheduleUpdate = video.scheduledUpdate
60 this.originallyPublishedAt = video.originallyPublishedAt
61 ? new Date(video.originallyPublishedAt)
64 this.pluginData = video.pluginData
67 patch (values: { [ id: string ]: any }) {
68 Object.keys(values).forEach((key) => {
69 this[key] = values[key]
72 // If schedule publication, the video is private and will be changed to public privacy
73 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
74 const updateAt = new Date(values['schedulePublicationAt'])
75 updateAt.setSeconds(0)
77 this.privacy = VideoPrivacy.PRIVATE
78 this.scheduleUpdate = {
79 updateAt: updateAt.toISOString(),
80 privacy: VideoPrivacy.PUBLIC
83 this.scheduleUpdate = null
86 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
87 if (this.originallyPublishedAt) {
88 const originallyPublishedAt = new Date(this.originallyPublishedAt)
89 this.originallyPublishedAt = originallyPublishedAt.toISOString()
92 // Use the same file than the preview for the thumbnail
93 if (this.previewfile) {
94 this.thumbnailfile = this.previewfile
100 category: this.category,
101 licence: this.licence,
102 language: this.language,
103 description: this.description,
104 support: this.support,
108 commentsEnabled: this.commentsEnabled,
109 downloadEnabled: this.downloadEnabled,
110 waitTranscoding: this.waitTranscoding,
111 channelId: this.channelId,
112 privacy: this.privacy,
113 originallyPublishedAt: this.originallyPublishedAt
116 // Special case if we scheduled an update
117 if (this.scheduleUpdate) {
118 Object.assign(json, {
119 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
120 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())