]>
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 | |
404b54e1 C |
23 | uuid?: string |
24 | id?: number | |
bbe0f064 | 25 | scheduleUpdate?: VideoScheduleUpdate |
c8034165 | 26 | originallyPublishedAt?: Date | string |
404b54e1 | 27 | |
7294aab0 C |
28 | pluginData?: any |
29 | ||
8ea1597f LD |
30 | constructor ( |
31 | video?: Video & { | |
32 | tags: string[], | |
33 | commentsEnabled: boolean, | |
34 | downloadEnabled: boolean, | |
35 | support: string, | |
36 | thumbnailUrl: string, | |
37 | previewUrl: string | |
38 | }) { | |
fbad87b0 C |
39 | if (video) { |
40 | this.id = video.id | |
41 | this.uuid = video.uuid | |
42 | this.category = video.category.id | |
43 | this.licence = video.licence.id | |
44 | this.language = video.language.id | |
45 | this.description = video.description | |
46 | this.name = video.name | |
47 | this.tags = video.tags | |
48 | this.nsfw = video.nsfw | |
49 | this.commentsEnabled = video.commentsEnabled | |
7f2cfe3a | 50 | this.downloadEnabled = video.downloadEnabled |
fbad87b0 C |
51 | this.waitTranscoding = video.waitTranscoding |
52 | this.channelId = video.channel.id | |
53 | this.privacy = video.privacy.id | |
54 | this.support = video.support | |
55 | this.thumbnailUrl = video.thumbnailUrl | |
56 | this.previewUrl = video.previewUrl | |
bbe0f064 | 57 | |
fbad87b0 | 58 | this.scheduleUpdate = video.scheduledUpdate |
6913f691 | 59 | this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null |
7294aab0 C |
60 | |
61 | this.pluginData = video.pluginData | |
cadb46d8 | 62 | } |
9d9597df C |
63 | } |
64 | ||
7294aab0 | 65 | patch (values: { [ id: string ]: any }) { |
404b54e1 | 66 | Object.keys(values).forEach((key) => { |
2186386c | 67 | this[ key ] = values[ key ] |
404b54e1 | 68 | }) |
bbe0f064 C |
69 | |
70 | // If schedule publication, the video is private and will be changed to public privacy | |
e94fc297 | 71 | if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) { |
c199c427 | 72 | const updateAt = new Date(values['schedulePublicationAt']) |
bbe0f064 C |
73 | updateAt.setSeconds(0) |
74 | ||
75 | this.privacy = VideoPrivacy.PRIVATE | |
76 | this.scheduleUpdate = { | |
77 | updateAt: updateAt.toISOString(), | |
78 | privacy: VideoPrivacy.PUBLIC | |
79 | } | |
e94fc297 C |
80 | } else { |
81 | this.scheduleUpdate = null | |
bbe0f064 | 82 | } |
c8034165 | 83 | |
84 | // Convert originallyPublishedAt to string so that function objectToFormData() works correctly | |
85 | if (this.originallyPublishedAt) { | |
86 | const originallyPublishedAt = new Date(values['originallyPublishedAt']) | |
87 | this.originallyPublishedAt = originallyPublishedAt.toISOString() | |
88 | } | |
7b992a86 C |
89 | |
90 | // Use the same file than the preview for the thumbnail | |
91 | if (this.previewfile) { | |
92 | this.thumbnailfile = this.previewfile | |
93 | } | |
404b54e1 C |
94 | } |
95 | ||
bbe0f064 C |
96 | toFormPatch () { |
97 | const json = { | |
404b54e1 C |
98 | category: this.category, |
99 | licence: this.licence, | |
100 | language: this.language, | |
101 | description: this.description, | |
07fa4c97 | 102 | support: this.support, |
404b54e1 C |
103 | name: this.name, |
104 | tags: this.tags, | |
105 | nsfw: this.nsfw, | |
47564bbe | 106 | commentsEnabled: this.commentsEnabled, |
7f2cfe3a | 107 | downloadEnabled: this.downloadEnabled, |
2186386c | 108 | waitTranscoding: this.waitTranscoding, |
0f320037 | 109 | channelId: this.channelId, |
c8034165 | 110 | privacy: this.privacy, |
111 | originallyPublishedAt: this.originallyPublishedAt | |
404b54e1 | 112 | } |
bbe0f064 C |
113 | |
114 | // Special case if we scheduled an update | |
115 | if (this.scheduleUpdate) { | |
116 | Object.assign(json, { | |
117 | privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY, | |
118 | schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString()) | |
119 | }) | |
120 | } | |
121 | ||
122 | return json | |
404b54e1 C |
123 | } |
124 | } |