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