]>
Commit | Line | Data |
---|---|---|
fd45e8f4 | 1 | import { VideoPrivacy } from '../../../../../shared/models/videos/video-privacy.enum' |
2186386c | 2 | import { VideoUpdate } from '../../../../../shared/models/videos' |
bbe0f064 | 3 | import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' |
fbad87b0 | 4 | import { Video } from '../../../../../shared/models/videos/video.model' |
9d9597df | 5 | |
2186386c | 6 | export class VideoEdit implements VideoUpdate { |
bbe0f064 C |
7 | static readonly SPECIAL_SCHEDULED_PRIVACY = -1 |
8 | ||
404b54e1 C |
9 | category: number |
10 | licence: number | |
9d3ef9fe | 11 | language: string |
404b54e1 C |
12 | description: string |
13 | name: string | |
14 | tags: string[] | |
15 | nsfw: boolean | |
47564bbe | 16 | commentsEnabled: boolean |
2186386c | 17 | waitTranscoding: boolean |
0f320037 | 18 | channelId: number |
fd45e8f4 | 19 | privacy: VideoPrivacy |
07fa4c97 | 20 | support: string |
6de36768 C |
21 | thumbnailfile?: any |
22 | previewfile?: any | |
23 | thumbnailUrl: string | |
24 | previewUrl: string | |
404b54e1 C |
25 | uuid?: string |
26 | id?: number | |
bbe0f064 | 27 | scheduleUpdate?: VideoScheduleUpdate |
244b4ae3 | 28 | [key: string]: any |
404b54e1 | 29 | |
fbad87b0 C |
30 | constructor (video?: Video & { tags: string[], commentsEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) { |
31 | if (video) { | |
32 | this.id = video.id | |
33 | this.uuid = video.uuid | |
34 | this.category = video.category.id | |
35 | this.licence = video.licence.id | |
36 | this.language = video.language.id | |
37 | this.description = video.description | |
38 | this.name = video.name | |
39 | this.tags = video.tags | |
40 | this.nsfw = video.nsfw | |
41 | this.commentsEnabled = video.commentsEnabled | |
42 | this.waitTranscoding = video.waitTranscoding | |
43 | this.channelId = video.channel.id | |
44 | this.privacy = video.privacy.id | |
45 | this.support = video.support | |
46 | this.thumbnailUrl = video.thumbnailUrl | |
47 | this.previewUrl = video.previewUrl | |
bbe0f064 | 48 | |
fbad87b0 | 49 | this.scheduleUpdate = video.scheduledUpdate |
cadb46d8 | 50 | } |
9d9597df C |
51 | } |
52 | ||
244b4ae3 | 53 | patch (values: any) { |
404b54e1 | 54 | Object.keys(values).forEach((key) => { |
2186386c | 55 | this[ key ] = values[ key ] |
404b54e1 | 56 | }) |
bbe0f064 C |
57 | |
58 | // If schedule publication, the video is private and will be changed to public privacy | |
e94fc297 | 59 | if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) { |
bbe0f064 C |
60 | const updateAt = (values['schedulePublicationAt'] as Date) |
61 | updateAt.setSeconds(0) | |
62 | ||
63 | this.privacy = VideoPrivacy.PRIVATE | |
64 | this.scheduleUpdate = { | |
65 | updateAt: updateAt.toISOString(), | |
66 | privacy: VideoPrivacy.PUBLIC | |
67 | } | |
e94fc297 C |
68 | } else { |
69 | this.scheduleUpdate = null | |
bbe0f064 | 70 | } |
404b54e1 C |
71 | } |
72 | ||
bbe0f064 C |
73 | toFormPatch () { |
74 | const json = { | |
404b54e1 C |
75 | category: this.category, |
76 | licence: this.licence, | |
77 | language: this.language, | |
78 | description: this.description, | |
07fa4c97 | 79 | support: this.support, |
404b54e1 C |
80 | name: this.name, |
81 | tags: this.tags, | |
82 | nsfw: this.nsfw, | |
47564bbe | 83 | commentsEnabled: this.commentsEnabled, |
2186386c | 84 | waitTranscoding: this.waitTranscoding, |
0f320037 | 85 | channelId: this.channelId, |
fd45e8f4 | 86 | privacy: this.privacy |
404b54e1 | 87 | } |
bbe0f064 C |
88 | |
89 | // Special case if we scheduled an update | |
90 | if (this.scheduleUpdate) { | |
91 | Object.assign(json, { | |
92 | privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY, | |
93 | schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString()) | |
94 | }) | |
95 | } | |
96 | ||
97 | return json | |
404b54e1 C |
98 | } |
99 | } |