]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Video, VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models' |
9d9597df | 2 | |
2186386c | 3 | export class VideoEdit implements VideoUpdate { |
bbe0f064 C |
4 | static readonly SPECIAL_SCHEDULED_PRIVACY = -1 |
5 | ||
404b54e1 C |
6 | category: number |
7 | licence: number | |
9d3ef9fe | 8 | language: string |
404b54e1 C |
9 | description: string |
10 | name: string | |
11 | tags: string[] | |
12 | nsfw: boolean | |
47564bbe | 13 | commentsEnabled: boolean |
7f2cfe3a | 14 | downloadEnabled: boolean |
2186386c | 15 | waitTranscoding: boolean |
0f320037 | 16 | channelId: number |
fd45e8f4 | 17 | privacy: VideoPrivacy |
07fa4c97 | 18 | support: string |
6de36768 C |
19 | thumbnailfile?: any |
20 | previewfile?: any | |
21 | thumbnailUrl: string | |
22 | previewUrl: string | |
bbe0f064 | 23 | scheduleUpdate?: VideoScheduleUpdate |
c8034165 | 24 | originallyPublishedAt?: Date | string |
404b54e1 | 25 | |
2e80d256 C |
26 | id?: number |
27 | uuid?: string | |
28 | shortUUID?: string | |
29 | ||
7294aab0 C |
30 | pluginData?: any |
31 | ||
8ea1597f LD |
32 | constructor ( |
33 | video?: Video & { | |
9df52d66 C |
34 | tags: string[] |
35 | commentsEnabled: boolean | |
36 | downloadEnabled: boolean | |
37 | support: string | |
38 | thumbnailUrl: string | |
8ea1597f LD |
39 | previewUrl: string |
40 | }) { | |
fbad87b0 C |
41 | if (video) { |
42 | this.id = video.id | |
43 | this.uuid = video.uuid | |
11995157 | 44 | this.shortUUID = video.shortUUID |
fbad87b0 C |
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 | |
7f2cfe3a | 53 | this.downloadEnabled = video.downloadEnabled |
fbad87b0 C |
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 | |
bbe0f064 | 60 | |
fbad87b0 | 61 | this.scheduleUpdate = video.scheduledUpdate |
6913f691 | 62 | this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null |
7294aab0 C |
63 | |
64 | this.pluginData = video.pluginData | |
cadb46d8 | 65 | } |
9d9597df C |
66 | } |
67 | ||
7294aab0 | 68 | patch (values: { [ id: string ]: any }) { |
404b54e1 | 69 | Object.keys(values).forEach((key) => { |
9df52d66 | 70 | this[key] = values[key] |
404b54e1 | 71 | }) |
bbe0f064 C |
72 | |
73 | // If schedule publication, the video is private and will be changed to public privacy | |
e94fc297 | 74 | if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) { |
c199c427 | 75 | const updateAt = new Date(values['schedulePublicationAt']) |
bbe0f064 C |
76 | updateAt.setSeconds(0) |
77 | ||
78 | this.privacy = VideoPrivacy.PRIVATE | |
79 | this.scheduleUpdate = { | |
80 | updateAt: updateAt.toISOString(), | |
81 | privacy: VideoPrivacy.PUBLIC | |
82 | } | |
e94fc297 C |
83 | } else { |
84 | this.scheduleUpdate = null | |
bbe0f064 | 85 | } |
c8034165 | 86 | |
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() | |
91 | } | |
7b992a86 C |
92 | |
93 | // Use the same file than the preview for the thumbnail | |
94 | if (this.previewfile) { | |
95 | this.thumbnailfile = this.previewfile | |
96 | } | |
404b54e1 C |
97 | } |
98 | ||
bbe0f064 C |
99 | toFormPatch () { |
100 | const json = { | |
404b54e1 C |
101 | category: this.category, |
102 | licence: this.licence, | |
103 | language: this.language, | |
104 | description: this.description, | |
07fa4c97 | 105 | support: this.support, |
404b54e1 C |
106 | name: this.name, |
107 | tags: this.tags, | |
108 | nsfw: this.nsfw, | |
47564bbe | 109 | commentsEnabled: this.commentsEnabled, |
7f2cfe3a | 110 | downloadEnabled: this.downloadEnabled, |
2186386c | 111 | waitTranscoding: this.waitTranscoding, |
0f320037 | 112 | channelId: this.channelId, |
c8034165 | 113 | privacy: this.privacy, |
114 | originallyPublishedAt: this.originallyPublishedAt | |
404b54e1 | 115 | } |
bbe0f064 C |
116 | |
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()) | |
122 | }) | |
123 | } | |
124 | ||
125 | return json | |
404b54e1 C |
126 | } |
127 | } |