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