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