]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-edit.model.ts
Merge branch 'develop' into pr/1217
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-edit.model.ts
CommitLineData
fd45e8f4 1import { VideoPrivacy } from '../../../../../shared/models/videos/video-privacy.enum'
2186386c 2import { VideoUpdate } from '../../../../../shared/models/videos'
bbe0f064 3import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
fbad87b0 4import { Video } from '../../../../../shared/models/videos/video.model'
9d9597df 5
2186386c 6export 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
7f2cfe3a 17 downloadEnabled: boolean
2186386c 18 waitTranscoding: boolean
0f320037 19 channelId: number
fd45e8f4 20 privacy: VideoPrivacy
07fa4c97 21 support: string
6de36768
C
22 thumbnailfile?: any
23 previewfile?: any
24 thumbnailUrl: string
25 previewUrl: string
404b54e1
C
26 uuid?: string
27 id?: number
bbe0f064 28 scheduleUpdate?: VideoScheduleUpdate
404b54e1 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
cadb46d8 59 }
9d9597df
C
60 }
61
c199c427 62 patch (values: { [ id: string ]: string }) {
404b54e1 63 Object.keys(values).forEach((key) => {
2186386c 64 this[ key ] = values[ key ]
404b54e1 65 })
bbe0f064
C
66
67 // If schedule publication, the video is private and will be changed to public privacy
e94fc297 68 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
c199c427 69 const updateAt = new Date(values['schedulePublicationAt'])
bbe0f064
C
70 updateAt.setSeconds(0)
71
72 this.privacy = VideoPrivacy.PRIVATE
73 this.scheduleUpdate = {
74 updateAt: updateAt.toISOString(),
75 privacy: VideoPrivacy.PUBLIC
76 }
e94fc297
C
77 } else {
78 this.scheduleUpdate = null
bbe0f064 79 }
404b54e1
C
80 }
81
bbe0f064
C
82 toFormPatch () {
83 const json = {
404b54e1
C
84 category: this.category,
85 licence: this.licence,
86 language: this.language,
87 description: this.description,
07fa4c97 88 support: this.support,
404b54e1
C
89 name: this.name,
90 tags: this.tags,
91 nsfw: this.nsfw,
47564bbe 92 commentsEnabled: this.commentsEnabled,
7f2cfe3a 93 downloadEnabled: this.downloadEnabled,
2186386c 94 waitTranscoding: this.waitTranscoding,
0f320037 95 channelId: this.channelId,
fd45e8f4 96 privacy: this.privacy
404b54e1 97 }
bbe0f064
C
98
99 // Special case if we scheduled an update
100 if (this.scheduleUpdate) {
101 Object.assign(json, {
102 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
103 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())
104 })
105 }
106
107 return json
404b54e1
C
108 }
109}