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