]>
Commit | Line | Data |
---|---|---|
3a0fb65c | 1 | import { AuthUser } from '@app/core' |
67ed6552 | 2 | import { User } from '@app/core/users/user.model' |
72493e44 | 3 | import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
69524f6e C |
4 | import { Account } from '@app/shared/shared-main/account/account.model' |
5 | import { Actor } from '@app/shared/shared-main/account/actor.model' | |
6 | import { VideoChannel } from '@app/shared/shared-main/video-channel/video-channel.model' | |
bd45d503 | 7 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
67ed6552 | 8 | import { |
f4796856 | 9 | ActorImage, |
67ed6552 C |
10 | ServerConfig, |
11 | UserRight, | |
12 | Video as VideoServerModel, | |
13 | VideoConstant, | |
14 | VideoPrivacy, | |
15 | VideoScheduleUpdate, | |
16 | VideoState | |
17 | } from '@shared/models' | |
92fb909c | 18 | |
69f616ab | 19 | export class Video implements VideoServerModel { |
22a16e36 C |
20 | byVideoChannel: string |
21 | byAccount: string | |
22 | ||
df98563e | 23 | createdAt: Date |
6d33593a | 24 | updatedAt: Date |
2922e048 | 25 | publishedAt: Date |
c8034165 | 26 | originallyPublishedAt: Date | string |
09700934 C |
27 | category: VideoConstant<number> |
28 | licence: VideoConstant<number> | |
9d3ef9fe | 29 | language: VideoConstant<string> |
2243730c | 30 | privacy: VideoConstant<VideoPrivacy> |
df98563e C |
31 | description: string |
32 | duration: number | |
33 | durationLabel: string | |
0a6658fd C |
34 | id: number |
35 | uuid: string | |
df98563e | 36 | isLocal: boolean |
df98563e | 37 | name: string |
60862425 | 38 | serverHost: string |
df98563e C |
39 | thumbnailPath: string |
40 | thumbnailUrl: string | |
5fb2e288 | 41 | |
c6c0fa6c C |
42 | isLive: boolean |
43 | ||
43f61d26 C |
44 | previewPath: string |
45 | previewUrl: string | |
5fb2e288 | 46 | |
d8755eed C |
47 | embedPath: string |
48 | embedUrl: string | |
5fb2e288 C |
49 | |
50 | url?: string | |
51 | ||
df98563e C |
52 | views: number |
53 | likes: number | |
54 | dislikes: number | |
55 | nsfw: boolean | |
b64c950a | 56 | |
c910f667 C |
57 | originInstanceUrl: string |
58 | originInstanceHost: string | |
59 | ||
2186386c C |
60 | waitTranscoding?: boolean |
61 | state?: VideoConstant<VideoState> | |
bbe0f064 | 62 | scheduledUpdate?: VideoScheduleUpdate |
191764f3 | 63 | blacklisted?: boolean |
5baee5fc | 64 | blockedReason?: string |
2186386c | 65 | |
b64c950a | 66 | account: { |
03e12d7c | 67 | id: number |
b64c950a C |
68 | name: string |
69 | displayName: string | |
70 | url: string | |
0f320037 | 71 | host: string |
f4796856 | 72 | avatar?: ActorImage |
0f320037 C |
73 | } |
74 | ||
75 | channel: { | |
76 | id: number | |
0f320037 C |
77 | name: string |
78 | displayName: string | |
79 | url: string | |
b64c950a | 80 | host: string |
f4796856 | 81 | avatar?: ActorImage |
b64c950a | 82 | } |
aff038cd | 83 | |
6e46de09 C |
84 | userHistory?: { |
85 | currentTime: number | |
86 | } | |
87 | ||
7294aab0 C |
88 | pluginData?: any |
89 | ||
191764f3 C |
90 | static buildClientUrl (videoUUID: string) { |
91 | return '/videos/watch/' + videoUUID | |
92 | } | |
93 | ||
7ce44a74 | 94 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 95 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 96 | |
d592e0a9 | 97 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 98 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 99 | this.category = hash.category |
df98563e | 100 | this.licence = hash.licence |
df98563e | 101 | this.language = hash.language |
2243730c | 102 | this.privacy = hash.privacy |
2186386c C |
103 | this.waitTranscoding = hash.waitTranscoding |
104 | this.state = hash.state | |
df98563e | 105 | this.description = hash.description |
c910f667 | 106 | |
c6c0fa6c C |
107 | this.isLive = hash.isLive |
108 | ||
df98563e | 109 | this.duration = hash.duration |
11b8762f | 110 | this.durationLabel = durationToString(hash.duration) |
c910f667 | 111 | |
df98563e | 112 | this.id = hash.id |
0a6658fd | 113 | this.uuid = hash.uuid |
c910f667 | 114 | |
df98563e | 115 | this.isLocal = hash.isLocal |
df98563e | 116 | this.name = hash.name |
c910f667 | 117 | |
df98563e | 118 | this.thumbnailPath = hash.thumbnailPath |
c6c0fa6c C |
119 | this.thumbnailUrl = this.thumbnailPath |
120 | ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) | |
121 | : null | |
c910f667 | 122 | |
43f61d26 | 123 | this.previewPath = hash.previewPath |
c6c0fa6c C |
124 | this.previewUrl = this.previewPath |
125 | ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath) | |
126 | : null | |
c910f667 | 127 | |
d8755eed | 128 | this.embedPath = hash.embedPath |
72493e44 | 129 | this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath) |
5fb2e288 C |
130 | |
131 | this.url = hash.url | |
c910f667 | 132 | |
df98563e C |
133 | this.views = hash.views |
134 | this.likes = hash.likes | |
135 | this.dislikes = hash.dislikes | |
c910f667 | 136 | |
df98563e | 137 | this.nsfw = hash.nsfw |
c910f667 | 138 | |
b64c950a | 139 | this.account = hash.account |
52d9f792 | 140 | this.channel = hash.channel |
4fd8aa32 | 141 | |
22a16e36 C |
142 | this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
143 | this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) | |
7ce44a74 C |
144 | |
145 | this.category.label = peertubeTranslate(this.category.label, translations) | |
146 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
147 | this.language.label = peertubeTranslate(this.language.label, translations) | |
148 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 149 | |
bbe0f064 | 150 | this.scheduledUpdate = hash.scheduledUpdate |
830b4faf C |
151 | this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null |
152 | ||
2186386c | 153 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) |
191764f3 C |
154 | |
155 | this.blacklisted = hash.blacklisted | |
5baee5fc | 156 | this.blockedReason = hash.blacklistedReason |
6e46de09 C |
157 | |
158 | this.userHistory = hash.userHistory | |
c910f667 C |
159 | |
160 | this.originInstanceHost = this.account.host | |
161 | this.originInstanceUrl = 'https://' + this.originInstanceHost | |
7294aab0 C |
162 | |
163 | this.pluginData = hash.pluginData | |
501bc6c2 C |
164 | } |
165 | ||
0883b324 C |
166 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
167 | // Video is not NSFW, skip | |
168 | if (this.nsfw === false) return false | |
169 | ||
170 | // Return user setting if logged in | |
171 | if (user) return user.nsfwPolicy !== 'display' | |
172 | ||
173 | // Return default instance config | |
174 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 175 | } |
3a0fb65c C |
176 | |
177 | isRemovableBy (user: AuthUser) { | |
178 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | |
179 | } | |
180 | ||
5baee5fc | 181 | isBlockableBy (user: AuthUser) { |
3487330d | 182 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true |
3a0fb65c C |
183 | } |
184 | ||
5baee5fc | 185 | isUnblockableBy (user: AuthUser) { |
3487330d | 186 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true |
3a0fb65c C |
187 | } |
188 | ||
189 | isUpdatableBy (user: AuthUser) { | |
190 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | |
191 | } | |
b764380a | 192 | |
f8c00564 C |
193 | isLiveInfoAvailableBy (user: AuthUser) { |
194 | return this.isLive && | |
195 | user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE)) | |
196 | } | |
197 | ||
b764380a C |
198 | canBeDuplicatedBy (user: AuthUser) { |
199 | return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) | |
200 | } | |
4ec25ae8 C |
201 | |
202 | getExactNumberOfViews () { | |
203 | if (this.views < 1000) return '' | |
204 | ||
205 | if (this.isLive) { | |
206 | return $localize`${this.views} viewers` | |
207 | } | |
208 | ||
209 | return $localize`${this.views} views` | |
210 | } | |
501bc6c2 | 211 | } |