]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
smaller miniature average size in fluid grid, updated admin instructions for global...
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
bfbd9128 2import { UserRight, Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
b64c950a 3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
40e87e9e 4import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
11b8762f 5import { durationToString, getAbsoluteAPIUrl } from '../misc/utils'
3dfa8494 6import { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
d3e91a5f 7import { Actor } from '@app/shared/actor/actor.model'
bbe0f064 8import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
3a0fb65c 9import { AuthUser } from '@app/core'
92fb909c 10
69f616ab 11export class Video implements VideoServerModel {
22a16e36
C
12 byVideoChannel: string
13 byAccount: string
14
d3e91a5f 15 accountAvatarUrl: string
52d9f792 16 videoChannelAvatarUrl: string
22a16e36 17
df98563e 18 createdAt: Date
6d33593a 19 updatedAt: Date
2922e048 20 publishedAt: Date
c8034165 21 originallyPublishedAt: Date | string
09700934
C
22 category: VideoConstant<number>
23 licence: VideoConstant<number>
9d3ef9fe 24 language: VideoConstant<string>
2243730c 25 privacy: VideoConstant<VideoPrivacy>
df98563e
C
26 description: string
27 duration: number
28 durationLabel: string
0a6658fd
C
29 id: number
30 uuid: string
df98563e 31 isLocal: boolean
df98563e 32 name: string
60862425 33 serverHost: string
df98563e
C
34 thumbnailPath: string
35 thumbnailUrl: string
5fb2e288 36
43f61d26
C
37 previewPath: string
38 previewUrl: string
5fb2e288 39
d8755eed
C
40 embedPath: string
41 embedUrl: string
5fb2e288
C
42
43 url?: string
44
df98563e
C
45 views: number
46 likes: number
47 dislikes: number
48 nsfw: boolean
b64c950a 49
c910f667
C
50 originInstanceUrl: string
51 originInstanceHost: string
52
2186386c
C
53 waitTranscoding?: boolean
54 state?: VideoConstant<VideoState>
bbe0f064 55 scheduledUpdate?: VideoScheduleUpdate
191764f3
C
56 blacklisted?: boolean
57 blacklistedReason?: string
2186386c 58
b64c950a 59 account: {
03e12d7c 60 id: number
b64c950a
C
61 name: string
62 displayName: string
63 url: string
0f320037 64 host: string
457bb213 65 avatar?: Avatar
0f320037
C
66 }
67
68 channel: {
69 id: number
0f320037
C
70 name: string
71 displayName: string
72 url: string
b64c950a 73 host: string
457bb213 74 avatar?: Avatar
b64c950a 75 }
aff038cd 76
6e46de09
C
77 userHistory?: {
78 currentTime: number
79 }
80
191764f3
C
81 static buildClientUrl (videoUUID: string) {
82 return '/videos/watch/' + videoUUID
83 }
84
7ce44a74 85 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 86 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 87
d592e0a9 88 this.createdAt = new Date(hash.createdAt.toString())
2922e048 89 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 90 this.category = hash.category
df98563e 91 this.licence = hash.licence
df98563e 92 this.language = hash.language
2243730c 93 this.privacy = hash.privacy
2186386c
C
94 this.waitTranscoding = hash.waitTranscoding
95 this.state = hash.state
df98563e 96 this.description = hash.description
c910f667 97
df98563e 98 this.duration = hash.duration
11b8762f 99 this.durationLabel = durationToString(hash.duration)
c910f667 100
df98563e 101 this.id = hash.id
0a6658fd 102 this.uuid = hash.uuid
c910f667 103
df98563e 104 this.isLocal = hash.isLocal
df98563e 105 this.name = hash.name
c910f667 106
df98563e 107 this.thumbnailPath = hash.thumbnailPath
5fb2e288 108 this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
c910f667 109
43f61d26 110 this.previewPath = hash.previewPath
5fb2e288 111 this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
c910f667 112
d8755eed 113 this.embedPath = hash.embedPath
5fb2e288
C
114 this.embedUrl = hash.embedUrl || (absoluteAPIUrl + hash.embedPath)
115
116 this.url = hash.url
c910f667 117
df98563e
C
118 this.views = hash.views
119 this.likes = hash.likes
120 this.dislikes = hash.dislikes
c910f667 121
df98563e 122 this.nsfw = hash.nsfw
c910f667 123
b64c950a 124 this.account = hash.account
52d9f792 125 this.channel = hash.channel
4fd8aa32 126
22a16e36
C
127 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
128 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
d3e91a5f 129 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
52d9f792 130 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
7ce44a74
C
131
132 this.category.label = peertubeTranslate(this.category.label, translations)
133 this.licence.label = peertubeTranslate(this.licence.label, translations)
134 this.language.label = peertubeTranslate(this.language.label, translations)
135 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 136
bbe0f064 137 this.scheduledUpdate = hash.scheduledUpdate
830b4faf
C
138 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
139
2186386c 140 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
191764f3
C
141
142 this.blacklisted = hash.blacklisted
143 this.blacklistedReason = hash.blacklistedReason
6e46de09
C
144
145 this.userHistory = hash.userHistory
c910f667
C
146
147 this.originInstanceHost = this.account.host
148 this.originInstanceUrl = 'https://' + this.originInstanceHost
501bc6c2
C
149 }
150
0883b324
C
151 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
152 // Video is not NSFW, skip
153 if (this.nsfw === false) return false
154
155 // Return user setting if logged in
156 if (user) return user.nsfwPolicy !== 'display'
157
158 // Return default instance config
159 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 160 }
3a0fb65c
C
161
162 isRemovableBy (user: AuthUser) {
163 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
164 }
165
166 isBlackistableBy (user: AuthUser) {
167 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
168 }
169
170 isUnblacklistableBy (user: AuthUser) {
171 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
172 }
173
174 isUpdatableBy (user: AuthUser) {
175 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
176 }
b764380a
C
177
178 canBeDuplicatedBy (user: AuthUser) {
179 return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
180 }
501bc6c2 181}