1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
3 import { VideoDetails } from './video-details.model'
4 import { objectKeysTyped } from '@shared/core-utils'
6 export class VideoEdit implements VideoUpdate {
7 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
16 commentsEnabled: boolean
17 downloadEnabled: boolean
18 waitTranscoding: boolean
26 scheduleUpdate?: VideoScheduleUpdate
27 originallyPublishedAt?: Date | string
35 constructor (video?: VideoDetails) {
39 this.uuid = video.uuid
40 this.shortUUID = video.shortUUID
41 this.category = video.category.id
42 this.licence = video.licence.id
43 this.language = video.language.id
44 this.description = video.description
45 this.name = video.name
46 this.tags = video.tags
47 this.nsfw = video.nsfw
48 this.waitTranscoding = video.waitTranscoding
49 this.channelId = video.channel.id
50 this.privacy = video.privacy.id
52 this.support = video.support
54 this.commentsEnabled = video.commentsEnabled
55 this.downloadEnabled = video.downloadEnabled
57 if (video.thumbnailPath) this.thumbnailUrl = getAbsoluteAPIUrl() + video.thumbnailPath
58 if (video.previewPath) this.previewUrl = getAbsoluteAPIUrl() + video.previewPath
60 this.scheduleUpdate = video.scheduledUpdate
61 this.originallyPublishedAt = video.originallyPublishedAt
62 ? new Date(video.originallyPublishedAt)
65 this.pluginData = video.pluginData
68 patch (values: { [ id: string ]: any }) {
69 objectKeysTyped(values).forEach(key => {
71 (this as any)[key] = values[key]
74 // If schedule publication, the video is private and will be changed to public privacy
75 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
76 const updateAt = new Date(values['schedulePublicationAt'])
77 updateAt.setSeconds(0)
79 this.privacy = VideoPrivacy.PRIVATE
80 this.scheduleUpdate = {
81 updateAt: updateAt.toISOString(),
82 privacy: VideoPrivacy.PUBLIC
85 this.scheduleUpdate = null
88 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
89 if (this.originallyPublishedAt) {
90 const originallyPublishedAt = new Date(this.originallyPublishedAt)
91 this.originallyPublishedAt = originallyPublishedAt.toISOString()
94 // Use the same file than the preview for the thumbnail
95 if (this.previewfile) {
96 this.thumbnailfile = this.previewfile
102 category: this.category,
103 licence: this.licence,
104 language: this.language,
105 description: this.description,
106 support: this.support,
110 commentsEnabled: this.commentsEnabled,
111 downloadEnabled: this.downloadEnabled,
112 waitTranscoding: this.waitTranscoding,
113 channelId: this.channelId,
114 privacy: this.privacy,
115 originallyPublishedAt: this.originallyPublishedAt
118 // Special case if we scheduled an update
119 if (this.scheduleUpdate) {
120 Object.assign(json, {
121 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
122 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())