diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/shared-main/video/video.model.ts | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-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.model.ts')
-rw-r--r-- | client/src/app/shared/shared-main/video/video.model.ts | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts new file mode 100644 index 000000000..3e6d6a38d --- /dev/null +++ b/client/src/app/shared/shared-main/video/video.model.ts | |||
@@ -0,0 +1,188 @@ | |||
1 | import { AuthUser } from '@app/core' | ||
2 | import { User } from '@app/core/users/user.model' | ||
3 | import { durationToString, getAbsoluteAPIUrl } from '@app/helpers' | ||
4 | import { | ||
5 | Avatar, | ||
6 | peertubeTranslate, | ||
7 | ServerConfig, | ||
8 | UserRight, | ||
9 | Video as VideoServerModel, | ||
10 | VideoConstant, | ||
11 | VideoPrivacy, | ||
12 | VideoScheduleUpdate, | ||
13 | VideoState | ||
14 | } from '@shared/models' | ||
15 | import { environment } from '../../../../environments/environment' | ||
16 | import { Actor } from '../account/actor.model' | ||
17 | |||
18 | export class Video implements VideoServerModel { | ||
19 | byVideoChannel: string | ||
20 | byAccount: string | ||
21 | |||
22 | accountAvatarUrl: string | ||
23 | videoChannelAvatarUrl: string | ||
24 | |||
25 | createdAt: Date | ||
26 | updatedAt: Date | ||
27 | publishedAt: Date | ||
28 | originallyPublishedAt: Date | string | ||
29 | category: VideoConstant<number> | ||
30 | licence: VideoConstant<number> | ||
31 | language: VideoConstant<string> | ||
32 | privacy: VideoConstant<VideoPrivacy> | ||
33 | description: string | ||
34 | duration: number | ||
35 | durationLabel: string | ||
36 | id: number | ||
37 | uuid: string | ||
38 | isLocal: boolean | ||
39 | name: string | ||
40 | serverHost: string | ||
41 | thumbnailPath: string | ||
42 | thumbnailUrl: string | ||
43 | |||
44 | previewPath: string | ||
45 | previewUrl: string | ||
46 | |||
47 | embedPath: string | ||
48 | embedUrl: string | ||
49 | |||
50 | url?: string | ||
51 | |||
52 | views: number | ||
53 | likes: number | ||
54 | dislikes: number | ||
55 | nsfw: boolean | ||
56 | |||
57 | originInstanceUrl: string | ||
58 | originInstanceHost: string | ||
59 | |||
60 | waitTranscoding?: boolean | ||
61 | state?: VideoConstant<VideoState> | ||
62 | scheduledUpdate?: VideoScheduleUpdate | ||
63 | blacklisted?: boolean | ||
64 | blockedReason?: string | ||
65 | |||
66 | account: { | ||
67 | id: number | ||
68 | name: string | ||
69 | displayName: string | ||
70 | url: string | ||
71 | host: string | ||
72 | avatar?: Avatar | ||
73 | } | ||
74 | |||
75 | channel: { | ||
76 | id: number | ||
77 | name: string | ||
78 | displayName: string | ||
79 | url: string | ||
80 | host: string | ||
81 | avatar?: Avatar | ||
82 | } | ||
83 | |||
84 | userHistory?: { | ||
85 | currentTime: number | ||
86 | } | ||
87 | |||
88 | static buildClientUrl (videoUUID: string) { | ||
89 | return '/videos/watch/' + videoUUID | ||
90 | } | ||
91 | |||
92 | constructor (hash: VideoServerModel, translations = {}) { | ||
93 | const absoluteAPIUrl = getAbsoluteAPIUrl() | ||
94 | |||
95 | this.createdAt = new Date(hash.createdAt.toString()) | ||
96 | this.publishedAt = new Date(hash.publishedAt.toString()) | ||
97 | this.category = hash.category | ||
98 | this.licence = hash.licence | ||
99 | this.language = hash.language | ||
100 | this.privacy = hash.privacy | ||
101 | this.waitTranscoding = hash.waitTranscoding | ||
102 | this.state = hash.state | ||
103 | this.description = hash.description | ||
104 | |||
105 | this.duration = hash.duration | ||
106 | this.durationLabel = durationToString(hash.duration) | ||
107 | |||
108 | this.id = hash.id | ||
109 | this.uuid = hash.uuid | ||
110 | |||
111 | this.isLocal = hash.isLocal | ||
112 | this.name = hash.name | ||
113 | |||
114 | this.thumbnailPath = hash.thumbnailPath | ||
115 | this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) | ||
116 | |||
117 | this.previewPath = hash.previewPath | ||
118 | this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath) | ||
119 | |||
120 | this.embedPath = hash.embedPath | ||
121 | this.embedUrl = hash.embedUrl || (environment.embedUrl + hash.embedPath) | ||
122 | |||
123 | this.url = hash.url | ||
124 | |||
125 | this.views = hash.views | ||
126 | this.likes = hash.likes | ||
127 | this.dislikes = hash.dislikes | ||
128 | |||
129 | this.nsfw = hash.nsfw | ||
130 | |||
131 | this.account = hash.account | ||
132 | this.channel = hash.channel | ||
133 | |||
134 | this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) | ||
135 | this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) | ||
136 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | ||
137 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) | ||
138 | |||
139 | this.category.label = peertubeTranslate(this.category.label, translations) | ||
140 | this.licence.label = peertubeTranslate(this.licence.label, translations) | ||
141 | this.language.label = peertubeTranslate(this.language.label, translations) | ||
142 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | ||
143 | |||
144 | this.scheduledUpdate = hash.scheduledUpdate | ||
145 | this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null | ||
146 | |||
147 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) | ||
148 | |||
149 | this.blacklisted = hash.blacklisted | ||
150 | this.blockedReason = hash.blacklistedReason | ||
151 | |||
152 | this.userHistory = hash.userHistory | ||
153 | |||
154 | this.originInstanceHost = this.account.host | ||
155 | this.originInstanceUrl = 'https://' + this.originInstanceHost | ||
156 | } | ||
157 | |||
158 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { | ||
159 | // Video is not NSFW, skip | ||
160 | if (this.nsfw === false) return false | ||
161 | |||
162 | // Return user setting if logged in | ||
163 | if (user) return user.nsfwPolicy !== 'display' | ||
164 | |||
165 | // Return default instance config | ||
166 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | ||
167 | } | ||
168 | |||
169 | isRemovableBy (user: AuthUser) { | ||
170 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | ||
171 | } | ||
172 | |||
173 | isBlockableBy (user: AuthUser) { | ||
174 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | ||
175 | } | ||
176 | |||
177 | isUnblockableBy (user: AuthUser) { | ||
178 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | ||
179 | } | ||
180 | |||
181 | isUpdatableBy (user: AuthUser) { | ||
182 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | ||
183 | } | ||
184 | |||
185 | canBeDuplicatedBy (user: AuthUser) { | ||
186 | return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) | ||
187 | } | ||
188 | } | ||