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