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