]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Handle sort in rss
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
76d36e0b 1import { Account } from '@app/shared/account/account.model'
202f6b6c 2import { User } from '../'
63c4db6d 3import { Video as VideoServerModel } from '../../../../../shared'
b64c950a 4import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
09700934 5import { VideoConstant } from '../../../../../shared/models/videos/video.model'
c5911fd3 6import { getAbsoluteAPIUrl } from '../misc/utils'
92fb909c 7
69f616ab 8export class Video implements VideoServerModel {
df98563e
C
9 by: string
10 createdAt: Date
6d33593a 11 updatedAt: Date
2922e048 12 publishedAt: Date
09700934
C
13 category: VideoConstant<number>
14 licence: VideoConstant<number>
15 language: VideoConstant<number>
df98563e
C
16 description: string
17 duration: number
18 durationLabel: string
0a6658fd
C
19 id: number
20 uuid: string
df98563e 21 isLocal: boolean
df98563e 22 name: string
60862425 23 serverHost: string
df98563e
C
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
b64c950a
C
34
35 account: {
36 name: string
37 displayName: string
38 url: string
39 host: string
40 avatar: Avatar
41 }
aff038cd 42
df98563e 43 private static createDurationString (duration: number) {
f6aec1b0
LD
44 const hours = Math.floor(duration / 3600)
45 const minutes = Math.floor(duration % 3600 / 60)
df98563e 46 const seconds = duration % 60
f6aec1b0 47
df98563e
C
48 const minutesPadding = minutes >= 10 ? '' : '0'
49 const secondsPadding = seconds >= 10 ? '' : '0'
f6aec1b0 50 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
4fd8aa32 51
f6aec1b0
LD
52 return displayedHours + minutesPadding +
53 minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
54 }
55
404b54e1 56 constructor (hash: VideoServerModel) {
c5911fd3 57 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 58
d592e0a9 59 this.createdAt = new Date(hash.createdAt.toString())
2922e048 60 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 61 this.category = hash.category
df98563e 62 this.licence = hash.licence
df98563e
C
63 this.language = hash.language
64 this.description = hash.description
65 this.duration = hash.duration
66 this.durationLabel = Video.createDurationString(hash.duration)
67 this.id = hash.id
0a6658fd 68 this.uuid = hash.uuid
df98563e 69 this.isLocal = hash.isLocal
df98563e 70 this.name = hash.name
df98563e 71 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 72 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 73 this.previewPath = hash.previewPath
c6e0bfbf 74 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 75 this.embedPath = hash.embedPath
c6e0bfbf 76 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
77 this.views = hash.views
78 this.likes = hash.likes
79 this.dislikes = hash.dislikes
80 this.nsfw = hash.nsfw
b64c950a 81 this.account = hash.account
4fd8aa32 82
b64c950a 83 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host)
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}