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