]>
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' |
c5911fd3 | 4 | import { getAbsoluteAPIUrl } from '../misc/utils' |
92fb909c | 5 | |
69f616ab | 6 | export class Video implements VideoServerModel { |
b1fa3eba | 7 | accountName: string |
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 | |
b1fa3eba | 35 | account: Account |
aff038cd | 36 | |
df98563e C |
37 | private static createDurationString (duration: number) { |
38 | const minutes = Math.floor(duration / 60) | |
39 | const seconds = duration % 60 | |
40 | const minutesPadding = minutes >= 10 ? '' : '0' | |
41 | const secondsPadding = seconds >= 10 ? '' : '0' | |
4fd8aa32 | 42 | |
df98563e | 43 | return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() |
4fd8aa32 C |
44 | } |
45 | ||
404b54e1 | 46 | constructor (hash: VideoServerModel) { |
c5911fd3 | 47 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 48 | |
b1fa3eba | 49 | this.accountName = hash.accountName |
d592e0a9 | 50 | this.createdAt = new Date(hash.createdAt.toString()) |
df98563e C |
51 | this.categoryLabel = hash.categoryLabel |
52 | this.category = hash.category | |
53 | this.licenceLabel = hash.licenceLabel | |
54 | this.licence = hash.licence | |
55 | this.languageLabel = hash.languageLabel | |
56 | this.language = hash.language | |
57 | this.description = hash.description | |
58 | this.duration = hash.duration | |
59 | this.durationLabel = Video.createDurationString(hash.duration) | |
60 | this.id = hash.id | |
0a6658fd | 61 | this.uuid = hash.uuid |
df98563e | 62 | this.isLocal = hash.isLocal |
df98563e | 63 | this.name = hash.name |
60862425 | 64 | this.serverHost = hash.serverHost |
df98563e | 65 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 66 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 67 | this.previewPath = hash.previewPath |
c6e0bfbf | 68 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 69 | this.embedPath = hash.embedPath |
c6e0bfbf | 70 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
71 | this.views = hash.views |
72 | this.likes = hash.likes | |
73 | this.dislikes = hash.dislikes | |
74 | this.nsfw = hash.nsfw | |
4fd8aa32 | 75 | |
76d36e0b | 76 | this.by = Account.CREATE_BY_STRING(hash.accountName, hash.serverHost) |
501bc6c2 C |
77 | } |
78 | ||
df98563e | 79 | isVideoNSFWForUser (user: User) { |
92fb909c | 80 | // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... |
df98563e | 81 | return (this.nsfw && (!user || user.displayNSFW === false)) |
92fb909c | 82 | } |
501bc6c2 | 83 | } |