]>
Commit | Line | Data |
---|---|---|
76d36e0b | 1 | import { Account } from '@app/shared/account/account.model' |
202f6b6c | 2 | import { User } from '../' |
63c4db6d | 3 | import { Video as VideoServerModel } from '../../../../../shared' |
b64c950a | 4 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
c5911fd3 | 5 | import { getAbsoluteAPIUrl } from '../misc/utils' |
92fb909c | 6 | |
69f616ab | 7 | export class Video implements VideoServerModel { |
df98563e C |
8 | by: string |
9 | createdAt: Date | |
6d33593a | 10 | updatedAt: Date |
df98563e C |
11 | categoryLabel: string |
12 | category: number | |
13 | licenceLabel: string | |
14 | licence: number | |
15 | languageLabel: string | |
16 | language: number | |
17 | description: string | |
18 | duration: number | |
19 | durationLabel: string | |
0a6658fd C |
20 | id: number |
21 | uuid: string | |
df98563e | 22 | isLocal: boolean |
df98563e | 23 | name: string |
60862425 | 24 | serverHost: string |
df98563e C |
25 | thumbnailPath: string |
26 | thumbnailUrl: string | |
43f61d26 C |
27 | previewPath: string |
28 | previewUrl: string | |
d8755eed C |
29 | embedPath: string |
30 | embedUrl: string | |
df98563e C |
31 | views: number |
32 | likes: number | |
33 | dislikes: number | |
34 | nsfw: boolean | |
b64c950a C |
35 | |
36 | account: { | |
37 | name: string | |
38 | displayName: string | |
39 | url: string | |
40 | host: string | |
41 | avatar: Avatar | |
42 | } | |
aff038cd | 43 | |
df98563e C |
44 | private static createDurationString (duration: number) { |
45 | const minutes = Math.floor(duration / 60) | |
46 | const seconds = duration % 60 | |
47 | const minutesPadding = minutes >= 10 ? '' : '0' | |
48 | const secondsPadding = seconds >= 10 ? '' : '0' | |
4fd8aa32 | 49 | |
df98563e | 50 | return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() |
4fd8aa32 C |
51 | } |
52 | ||
404b54e1 | 53 | constructor (hash: VideoServerModel) { |
c5911fd3 | 54 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 55 | |
d592e0a9 | 56 | this.createdAt = new Date(hash.createdAt.toString()) |
df98563e C |
57 | this.categoryLabel = hash.categoryLabel |
58 | this.category = hash.category | |
59 | this.licenceLabel = hash.licenceLabel | |
60 | this.licence = hash.licence | |
61 | this.languageLabel = hash.languageLabel | |
62 | this.language = hash.language | |
63 | this.description = hash.description | |
64 | this.duration = hash.duration | |
65 | this.durationLabel = Video.createDurationString(hash.duration) | |
66 | this.id = hash.id | |
0a6658fd | 67 | this.uuid = hash.uuid |
df98563e | 68 | this.isLocal = hash.isLocal |
df98563e | 69 | this.name = hash.name |
df98563e | 70 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 71 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 72 | this.previewPath = hash.previewPath |
c6e0bfbf | 73 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 74 | this.embedPath = hash.embedPath |
c6e0bfbf | 75 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
76 | this.views = hash.views |
77 | this.likes = hash.likes | |
78 | this.dislikes = hash.dislikes | |
79 | this.nsfw = hash.nsfw | |
b64c950a | 80 | this.account = hash.account |
4fd8aa32 | 81 | |
b64c950a | 82 | this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host) |
501bc6c2 C |
83 | } |
84 | ||
df98563e | 85 | isVideoNSFWForUser (user: User) { |
92fb909c | 86 | // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... |
df98563e | 87 | return (this.nsfw && (!user || user.displayNSFW === false)) |
92fb909c | 88 | } |
501bc6c2 | 89 | } |