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