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