]>
Commit | Line | Data |
---|---|---|
202f6b6c | 1 | import { User } from '../' |
2243730c | 2 | import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared' |
b64c950a | 3 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
09700934 | 4 | import { VideoConstant } from '../../../../../shared/models/videos/video.model' |
c5911fd3 | 5 | import { getAbsoluteAPIUrl } from '../misc/utils' |
0883b324 | 6 | import { ServerConfig } from '../../../../../shared/models' |
d3e91a5f | 7 | import { Actor } from '@app/shared/actor/actor.model' |
92fb909c | 8 | |
69f616ab | 9 | export class Video implements VideoServerModel { |
df98563e | 10 | by: string |
d3e91a5f | 11 | accountAvatarUrl: string |
df98563e | 12 | createdAt: Date |
6d33593a | 13 | updatedAt: Date |
2922e048 | 14 | publishedAt: Date |
09700934 C |
15 | category: VideoConstant<number> |
16 | licence: VideoConstant<number> | |
9d3ef9fe | 17 | language: VideoConstant<string> |
2243730c | 18 | privacy: VideoConstant<VideoPrivacy> |
df98563e C |
19 | description: string |
20 | duration: number | |
21 | durationLabel: string | |
0a6658fd C |
22 | id: number |
23 | uuid: string | |
df98563e | 24 | isLocal: boolean |
df98563e | 25 | name: string |
60862425 | 26 | serverHost: string |
df98563e C |
27 | thumbnailPath: string |
28 | thumbnailUrl: string | |
43f61d26 C |
29 | previewPath: string |
30 | previewUrl: string | |
d8755eed C |
31 | embedPath: string |
32 | embedUrl: string | |
df98563e C |
33 | views: number |
34 | likes: number | |
35 | dislikes: number | |
36 | nsfw: boolean | |
b64c950a C |
37 | |
38 | account: { | |
03e12d7c C |
39 | id: number |
40 | uuid: string | |
b64c950a C |
41 | name: string |
42 | displayName: string | |
43 | url: string | |
44 | host: string | |
45 | avatar: Avatar | |
46 | } | |
aff038cd | 47 | |
df98563e | 48 | private static createDurationString (duration: number) { |
f6aec1b0 LD |
49 | const hours = Math.floor(duration / 3600) |
50 | const minutes = Math.floor(duration % 3600 / 60) | |
df98563e | 51 | const seconds = duration % 60 |
f6aec1b0 | 52 | |
df98563e C |
53 | const minutesPadding = minutes >= 10 ? '' : '0' |
54 | const secondsPadding = seconds >= 10 ? '' : '0' | |
f6aec1b0 | 55 | const displayedHours = hours > 0 ? hours.toString() + ':' : '' |
4fd8aa32 | 56 | |
f6aec1b0 LD |
57 | return displayedHours + minutesPadding + |
58 | minutes.toString() + ':' + secondsPadding + seconds.toString() | |
4fd8aa32 C |
59 | } |
60 | ||
404b54e1 | 61 | constructor (hash: VideoServerModel) { |
c5911fd3 | 62 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 63 | |
d592e0a9 | 64 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 65 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 66 | this.category = hash.category |
df98563e | 67 | this.licence = hash.licence |
df98563e | 68 | this.language = hash.language |
2243730c | 69 | this.privacy = hash.privacy |
df98563e C |
70 | this.description = hash.description |
71 | this.duration = hash.duration | |
72 | this.durationLabel = Video.createDurationString(hash.duration) | |
73 | this.id = hash.id | |
0a6658fd | 74 | this.uuid = hash.uuid |
df98563e | 75 | this.isLocal = hash.isLocal |
df98563e | 76 | this.name = hash.name |
df98563e | 77 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 78 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 79 | this.previewPath = hash.previewPath |
c6e0bfbf | 80 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 81 | this.embedPath = hash.embedPath |
c6e0bfbf | 82 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
83 | this.views = hash.views |
84 | this.likes = hash.likes | |
85 | this.dislikes = hash.dislikes | |
86 | this.nsfw = hash.nsfw | |
b64c950a | 87 | this.account = hash.account |
4fd8aa32 | 88 | |
d3e91a5f C |
89 | this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
90 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | |
501bc6c2 C |
91 | } |
92 | ||
0883b324 C |
93 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
94 | // Video is not NSFW, skip | |
95 | if (this.nsfw === false) return false | |
96 | ||
97 | // Return user setting if logged in | |
98 | if (user) return user.nsfwPolicy !== 'display' | |
99 | ||
100 | // Return default instance config | |
101 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 102 | } |
501bc6c2 | 103 | } |