]>
Commit | Line | Data |
---|---|---|
404b54e1 | 1 | import { Video as VideoServerModel } from '../../../../../shared' |
202f6b6c | 2 | import { User } from '../' |
92fb909c | 3 | |
69f616ab | 4 | export class Video implements VideoServerModel { |
1e1265b3 | 5 | account: string |
df98563e C |
6 | by: string |
7 | createdAt: Date | |
6d33593a | 8 | updatedAt: Date |
df98563e C |
9 | categoryLabel: string |
10 | category: number | |
11 | licenceLabel: string | |
12 | licence: number | |
13 | languageLabel: string | |
14 | language: number | |
15 | description: string | |
16 | duration: number | |
17 | durationLabel: string | |
0a6658fd C |
18 | id: number |
19 | uuid: string | |
df98563e | 20 | isLocal: boolean |
df98563e | 21 | name: string |
60862425 | 22 | serverHost: string |
df98563e C |
23 | tags: string[] |
24 | thumbnailPath: string | |
25 | thumbnailUrl: string | |
43f61d26 C |
26 | previewPath: string |
27 | previewUrl: string | |
d8755eed C |
28 | embedPath: string |
29 | embedUrl: string | |
df98563e C |
30 | views: number |
31 | likes: number | |
32 | dislikes: number | |
33 | nsfw: boolean | |
aff038cd | 34 | |
60862425 C |
35 | private static createByString (account: string, serverHost: string) { |
36 | return account + '@' + serverHost | |
aff038cd C |
37 | } |
38 | ||
df98563e C |
39 | private static createDurationString (duration: number) { |
40 | const minutes = Math.floor(duration / 60) | |
41 | const seconds = duration % 60 | |
42 | const minutesPadding = minutes >= 10 ? '' : '0' | |
43 | const secondsPadding = seconds >= 10 ? '' : '0' | |
4fd8aa32 | 44 | |
df98563e | 45 | return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() |
4fd8aa32 C |
46 | } |
47 | ||
404b54e1 | 48 | constructor (hash: VideoServerModel) { |
c6e0bfbf C |
49 | let absoluteAPIUrl = API_URL |
50 | if (!absoluteAPIUrl) { | |
51 | // The API is on the same domain | |
52 | absoluteAPIUrl = window.location.origin | |
53 | } | |
54 | ||
1e1265b3 | 55 | this.account = hash.account |
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 |
60862425 | 70 | this.serverHost = hash.serverHost |
df98563e C |
71 | this.tags = hash.tags |
72 | this.thumbnailPath = hash.thumbnailPath | |
c6e0bfbf | 73 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 74 | this.previewPath = hash.previewPath |
c6e0bfbf | 75 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 76 | this.embedPath = hash.embedPath |
c6e0bfbf | 77 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
78 | this.views = hash.views |
79 | this.likes = hash.likes | |
80 | this.dislikes = hash.dislikes | |
81 | this.nsfw = hash.nsfw | |
4fd8aa32 | 82 | |
60862425 | 83 | this.by = Video.createByString(hash.account, hash.serverHost) |
501bc6c2 C |
84 | } |
85 | ||
df98563e | 86 | isVideoNSFWForUser (user: User) { |
92fb909c | 87 | // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos... |
df98563e | 88 | return (this.nsfw && (!user || user.displayNSFW === false)) |
92fb909c | 89 | } |
501bc6c2 | 90 | } |