]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/video/video-edit.model.ts
Implement two factor in client
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video-edit.model.ts
1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
3 import { VideoDetails } from './video-details.model'
4
5 export class VideoEdit implements VideoUpdate {
6 static readonly SPECIAL_SCHEDULED_PRIVACY = -1
7
8 category: number
9 licence: number
10 language: string
11 description: string
12 name: string
13 tags: string[]
14 nsfw: boolean
15 commentsEnabled: boolean
16 downloadEnabled: boolean
17 waitTranscoding: boolean
18 channelId: number
19 privacy: VideoPrivacy
20 support: string
21 thumbnailfile?: any
22 previewfile?: any
23 thumbnailUrl: string
24 previewUrl: string
25 scheduleUpdate?: VideoScheduleUpdate
26 originallyPublishedAt?: Date | string
27
28 id?: number
29 uuid?: string
30 shortUUID?: string
31
32 pluginData?: any
33
34 constructor (video?: VideoDetails) {
35 if (!video) return
36
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
50 this.commentsEnabled = video.commentsEnabled
51 this.downloadEnabled = video.downloadEnabled
52
53 if (video.thumbnailPath) this.thumbnailUrl = getAbsoluteAPIUrl() + video.thumbnailPath
54 if (video.previewPath) this.previewUrl = getAbsoluteAPIUrl() + video.previewPath
55
56 this.scheduleUpdate = video.scheduledUpdate
57 this.originallyPublishedAt = video.originallyPublishedAt
58 ? new Date(video.originallyPublishedAt)
59 : null
60
61 this.pluginData = video.pluginData
62 }
63
64 patch (values: { [ id: string ]: any }) {
65 Object.keys(values).forEach((key) => {
66 this[key] = values[key]
67 })
68
69 // If schedule publication, the video is private and will be changed to public privacy
70 if (parseInt(values['privacy'], 10) === VideoEdit.SPECIAL_SCHEDULED_PRIVACY) {
71 const updateAt = new Date(values['schedulePublicationAt'])
72 updateAt.setSeconds(0)
73
74 this.privacy = VideoPrivacy.PRIVATE
75 this.scheduleUpdate = {
76 updateAt: updateAt.toISOString(),
77 privacy: VideoPrivacy.PUBLIC
78 }
79 } else {
80 this.scheduleUpdate = null
81 }
82
83 // Convert originallyPublishedAt to string so that function objectToFormData() works correctly
84 if (this.originallyPublishedAt) {
85 const originallyPublishedAt = new Date(this.originallyPublishedAt)
86 this.originallyPublishedAt = originallyPublishedAt.toISOString()
87 }
88
89 // Use the same file than the preview for the thumbnail
90 if (this.previewfile) {
91 this.thumbnailfile = this.previewfile
92 }
93 }
94
95 toFormPatch () {
96 const json = {
97 category: this.category,
98 licence: this.licence,
99 language: this.language,
100 description: this.description,
101 support: this.support,
102 name: this.name,
103 tags: this.tags,
104 nsfw: this.nsfw,
105 commentsEnabled: this.commentsEnabled,
106 downloadEnabled: this.downloadEnabled,
107 waitTranscoding: this.waitTranscoding,
108 channelId: this.channelId,
109 privacy: this.privacy,
110 originallyPublishedAt: this.originallyPublishedAt
111 }
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
122 }
123 }