aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main/video/video-edit.model.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-main/video/video-edit.model.ts
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/shared-main/video/video-edit.model.ts')
-rw-r--r--client/src/app/shared/shared-main/video/video-edit.model.ts120
1 files changed, 120 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/video/video-edit.model.ts b/client/src/app/shared/shared-main/video/video-edit.model.ts
new file mode 100644
index 000000000..6a529e052
--- /dev/null
+++ b/client/src/app/shared/shared-main/video/video-edit.model.ts
@@ -0,0 +1,120 @@
1import { Video, VideoPrivacy, VideoScheduleUpdate, VideoUpdate } from '@shared/models'
2
3export 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}