]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/video/video-edit.model.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-edit.model.ts
CommitLineData
0146f351
C
1import { getAbsoluteAPIUrl } from '@app/helpers'
2import { VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
3import { VideoDetails } from './video-details.model'
54909304 4import { objectKeysTyped } from '@shared/core-utils'
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
bbe0f064 26 scheduleUpdate?: VideoScheduleUpdate
c8034165 27 originallyPublishedAt?: Date | string
404b54e1 28
2e80d256
C
29 id?: number
30 uuid?: string
31 shortUUID?: string
32
7294aab0
C
33 pluginData?: any
34
0146f351
C
35 constructor (video?: VideoDetails) {
36 if (!video) return
bbe0f064 37
0146f351
C
38 this.id = video.id
39 this.uuid = video.uuid
40 this.shortUUID = video.shortUUID
41 this.category = video.category.id
42 this.licence = video.licence.id
43 this.language = video.language.id
44 this.description = video.description
45 this.name = video.name
46 this.tags = video.tags
47 this.nsfw = video.nsfw
48 this.waitTranscoding = video.waitTranscoding
49 this.channelId = video.channel.id
50 this.privacy = video.privacy.id
7a0bcd67
C
51
52 this.support = video.support
53
0146f351
C
54 this.commentsEnabled = video.commentsEnabled
55 this.downloadEnabled = video.downloadEnabled
7294aab0 56
0146f351
C
57 if (video.thumbnailPath) this.thumbnailUrl = getAbsoluteAPIUrl() + video.thumbnailPath
58 if (video.previewPath) this.previewUrl = getAbsoluteAPIUrl() + video.previewPath
59
60 this.scheduleUpdate = video.scheduledUpdate
61 this.originallyPublishedAt = video.originallyPublishedAt
62 ? new Date(video.originallyPublishedAt)
63 : null
64
65 this.pluginData = video.pluginData
9d9597df
C
66 }
67
7294aab0 68 patch (values: { [ id: string ]: any }) {
54909304
C
69 objectKeysTyped(values).forEach(key => {
70 // FIXME: typings
71 (this as any)[key] = values[key]
404b54e1 72 })
bbe0f064
C
73
74 // If schedule publication, the video is private and will be changed to public privacy
e94fc297 75 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
c199c427 76 const updateAt = new Date(values['schedulePublicationAt'])
bbe0f064
C
77 updateAt.setSeconds(0)
78
79 this.privacy = VideoPrivacy.PRIVATE
80 this.scheduleUpdate = {
81 updateAt: updateAt.toISOString(),
82 privacy: VideoPrivacy.PUBLIC
83 }
e94fc297
C
84 } else {
85 this.scheduleUpdate = null
bbe0f064 86 }
c8034165 87
88 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
89 if (this.originallyPublishedAt) {
0146f351 90 const originallyPublishedAt = new Date(this.originallyPublishedAt)
c8034165 91 this.originallyPublishedAt = originallyPublishedAt.toISOString()
92 }
7b992a86
C
93
94 // Use the same file than the preview for the thumbnail
95 if (this.previewfile) {
96 this.thumbnailfile = this.previewfile
97 }
404b54e1
C
98 }
99
bbe0f064
C
100 toFormPatch () {
101 const json = {
404b54e1
C
102 category: this.category,
103 licence: this.licence,
104 language: this.language,
105 description: this.description,
07fa4c97 106 support: this.support,
404b54e1
C
107 name: this.name,
108 tags: this.tags,
109 nsfw: this.nsfw,
47564bbe 110 commentsEnabled: this.commentsEnabled,
7f2cfe3a 111 downloadEnabled: this.downloadEnabled,
2186386c 112 waitTranscoding: this.waitTranscoding,
0f320037 113 channelId: this.channelId,
c8034165 114 privacy: this.privacy,
115 originallyPublishedAt: this.originallyPublishedAt
404b54e1 116 }
bbe0f064
C
117
118 // Special case if we scheduled an update
119 if (this.scheduleUpdate) {
120 Object.assign(json, {
121 privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY,
122 schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString())
123 })
124 }
125
126 return json
404b54e1
C
127 }
128}