]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video-edit.model.ts
Add downloadingEnabled property to video model
[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
156c50af 17 downloadingEnabled: 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
156c50af 30 constructor (video?: Video & { tags: string[], commentsEnabled: boolean, downloadingEnabled: boolean, support: string, thumbnailUrl: string, previewUrl: string }) {
fbad87b0
C
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
156c50af 42 this.downloadingEnabled = video.downloadingEnabled
fbad87b0
C
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
bbe0f064 49
fbad87b0 50 this.scheduleUpdate = video.scheduledUpdate
cadb46d8 51 }
9d9597df
C
52 }
53
404b54e1
C
54 patch (values: Object) {
55 Object.keys(values).forEach((key) => {
2186386c 56 this[ key ] = values[ key ]
404b54e1 57 })
bbe0f064
C
58
59 // If schedule publication, the video is private and will be changed to public privacy
e94fc297 60 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
bbe0f064
C
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 }
e94fc297
C
69 } else {
70 this.scheduleUpdate = null
bbe0f064 71 }
404b54e1
C
72 }
73
bbe0f064
C
74 toFormPatch () {
75 const json = {
404b54e1
C
76 category: this.category,
77 licence: this.licence,
78 language: this.language,
79 description: this.description,
07fa4c97 80 support: this.support,
404b54e1
C
81 name: this.name,
82 tags: this.tags,
83 nsfw: this.nsfw,
47564bbe 84 commentsEnabled: this.commentsEnabled,
156c50af 85 downloadingEnabled: this.downloadingEnabled,
2186386c 86 waitTranscoding: this.waitTranscoding,
0f320037 87 channelId: this.channelId,
fd45e8f4 88 privacy: this.privacy
404b54e1 89 }
bbe0f064
C
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
404b54e1
C
100 }
101}