]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Video, VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
2
3 export class VideoEdit implements VideoUpdate {
4 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
5
6 category: number
7 licence: number
8 language: string
9 description: string
10 name: string
11 tags: string[]
12 nsfw: boolean
13 commentsEnabled: boolean
14 downloadEnabled: boolean
15 waitTranscoding: boolean
16 channelId: number
17 privacy: VideoPrivacy
18 support: string
19 thumbnailfile?: any
20 previewfile?: any
21 thumbnailUrl: string
22 previewUrl: string
23 uuid?: string
24 id?: number
25 scheduleUpdate?: VideoScheduleUpdate
26 originallyPublishedAt?: Date | string
27
28 constructor (
29 video?: Video & {
30 tags: string[],
31 commentsEnabled: boolean,
32 downloadEnabled: boolean,
33 support: string,
34 thumbnailUrl: string,
35 previewUrl: string
36 }) {
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
48 this.downloadEnabled = video.downloadEnabled
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
55
56 this.scheduleUpdate = video.scheduledUpdate
57 this.originallyPublishedAt = video.originallyPublishedAt ? new Date(video.originallyPublishedAt) : null
58 }
59 }
60
61 patch (values: { [ id: string ]: string }) {
62 Object.keys(values).forEach((key) => {
63 this[ key ] = values[ key ]
64 })
65
66 // If schedule publication, the video is private and will be changed to public privacy
67 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
68 const updateAt = new Date(values['schedulePublicationAt'])
69 updateAt.setSeconds(0)
70
71 this.privacy = VideoPrivacy.PRIVATE
72 this.scheduleUpdate = {
73 updateAt: updateAt.toISOString(),
74 privacy: VideoPrivacy.PUBLIC
75 }
76 } else {
77 this.scheduleUpdate = null
78 }
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 }
85
86 // Use the same file than the preview for the thumbnail
87 if (this.previewfile) {
88 this.thumbnailfile = this.previewfile
89 }
90 }
91
92 toFormPatch () {
93 const json = {
94 category: this.category,
95 licence: this.licence,
96 language: this.language,
97 description: this.description,
98 support: this.support,
99 name: this.name,
100 tags: this.tags,
101 nsfw: this.nsfw,
102 commentsEnabled: this.commentsEnabled,
103 downloadEnabled: this.downloadEnabled,
104 waitTranscoding: this.waitTranscoding,
105 channelId: this.channelId,
106 privacy: this.privacy,
107 originallyPublishedAt: this.originallyPublishedAt
108 }
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
119 }
120 }