]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Use sequelize scopes
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
63c4db6d 2import { Video as VideoServerModel } from '../../../../../shared'
b1fa3eba 3import { Account } from '../../../../../shared/models/accounts'
63c4db6d 4import { environment } from '../../../environments/environment'
92fb909c 5
69f616ab 6export 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
60862425
C
37 private static createByString (account: string, serverHost: string) {
38 return account + '@' + serverHost
aff038cd
C
39 }
40
df98563e
C
41 private static createDurationString (duration: number) {
42 const minutes = Math.floor(duration / 60)
43 const seconds = duration % 60
44 const minutesPadding = minutes >= 10 ? '' : '0'
45 const secondsPadding = seconds >= 10 ? '' : '0'
4fd8aa32 46
df98563e 47 return minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
4fd8aa32
C
48 }
49
404b54e1 50 constructor (hash: VideoServerModel) {
63c4db6d 51 let absoluteAPIUrl = environment.apiUrl
c6e0bfbf
C
52 if (!absoluteAPIUrl) {
53 // The API is on the same domain
54 absoluteAPIUrl = window.location.origin
55 }
56
b1fa3eba 57 this.accountName = hash.accountName
d592e0a9 58 this.createdAt = new Date(hash.createdAt.toString())
df98563e
C
59 this.categoryLabel = hash.categoryLabel
60 this.category = hash.category
61 this.licenceLabel = hash.licenceLabel
62 this.licence = hash.licence
63 this.languageLabel = hash.languageLabel
64 this.language = hash.language
65 this.description = hash.description
66 this.duration = hash.duration
67 this.durationLabel = Video.createDurationString(hash.duration)
68 this.id = hash.id
0a6658fd 69 this.uuid = hash.uuid
df98563e 70 this.isLocal = hash.isLocal
df98563e 71 this.name = hash.name
60862425 72 this.serverHost = hash.serverHost
df98563e 73 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 74 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 75 this.previewPath = hash.previewPath
c6e0bfbf 76 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 77 this.embedPath = hash.embedPath
c6e0bfbf 78 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
79 this.views = hash.views
80 this.likes = hash.likes
81 this.dislikes = hash.dislikes
82 this.nsfw = hash.nsfw
4fd8aa32 83
b1fa3eba 84 this.by = Video.createByString(hash.accountName, hash.serverHost)
501bc6c2
C
85 }
86
df98563e 87 isVideoNSFWForUser (user: User) {
92fb909c 88 // If the video is NSFW and the user is not logged in, or the user does not want to display NSFW videos...
df98563e 89 return (this.nsfw && (!user || user.displayNSFW === false))
92fb909c 90 }
501bc6c2 91}