]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Rename messages locale to angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
2243730c 2import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared'
b64c950a 3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
09700934 4import { VideoConstant } from '../../../../../shared/models/videos/video.model'
c5911fd3 5import { getAbsoluteAPIUrl } from '../misc/utils'
0883b324 6import { ServerConfig } from '../../../../../shared/models'
d3e91a5f 7import { Actor } from '@app/shared/actor/actor.model'
92fb909c 8
69f616ab 9export 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
0f320037
C
44 host: string
45 avatar: Avatar
46 }
47
48 channel: {
49 id: number
50 uuid: string
51 name: string
52 displayName: string
53 url: string
b64c950a
C
54 host: string
55 avatar: Avatar
56 }
aff038cd 57
df98563e 58 private static createDurationString (duration: number) {
f6aec1b0
LD
59 const hours = Math.floor(duration / 3600)
60 const minutes = Math.floor(duration % 3600 / 60)
df98563e 61 const seconds = duration % 60
f6aec1b0 62
df98563e
C
63 const minutesPadding = minutes >= 10 ? '' : '0'
64 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 65 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 66
f6aec1b0
LD
67 return displayedHours + minutesPadding +
68 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
69 }
70
404b54e1 71 constructor (hash: VideoServerModel) {
c5911fd3 72 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 73
d592e0a9 74 this.createdAt = new Date(hash.createdAt.toString())
2922e048 75 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 76 this.category = hash.category
df98563e 77 this.licence = hash.licence
df98563e 78 this.language = hash.language
2243730c 79 this.privacy = hash.privacy
df98563e
C
80 this.description = hash.description
81 this.duration = hash.duration
82 this.durationLabel = Video.createDurationString(hash.duration)
83 this.id = hash.id
0a6658fd 84 this.uuid = hash.uuid
df98563e 85 this.isLocal = hash.isLocal
df98563e 86 this.name = hash.name
df98563e 87 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 88 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 89 this.previewPath = hash.previewPath
c6e0bfbf 90 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 91 this.embedPath = hash.embedPath
c6e0bfbf 92 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
93 this.views = hash.views
94 this.likes = hash.likes
95 this.dislikes = hash.dislikes
96 this.nsfw = hash.nsfw
b64c950a 97 this.account = hash.account
4fd8aa32 98
d3e91a5f
C
99 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
100 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
501bc6c2
C
101 }
102
0883b324
C
103 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
104 // Video is not NSFW, skip
105 if (this.nsfw === false) return false
106
107 // Return user setting if logged in
108 if (user) return user.nsfwPolicy !== 'display'
109
110 // Return default instance config
111 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 112 }
501bc6c2 113}