]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video/video.model.ts
Add audio support in upload
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video.model.ts
CommitLineData
202f6b6c 1import { User } from '../'
3a0fb65c 2import { PlaylistElement, 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
43f61d26
C
36 previewPath: string
37 previewUrl: string
d8755eed
C
38 embedPath: string
39 embedUrl: string
df98563e
C
40 views: number
41 likes: number
42 dislikes: number
43 nsfw: boolean
b64c950a 44
2186386c
C
45 waitTranscoding?: boolean
46 state?: VideoConstant<VideoState>
bbe0f064 47 scheduledUpdate?: VideoScheduleUpdate
191764f3
C
48 blacklisted?: boolean
49 blacklistedReason?: string
2186386c 50
c5a1ae50
C
51 playlistElement?: PlaylistElement
52
b64c950a 53 account: {
03e12d7c
C
54 id: number
55 uuid: string
b64c950a
C
56 name: string
57 displayName: string
58 url: string
0f320037 59 host: string
457bb213 60 avatar?: Avatar
0f320037
C
61 }
62
63 channel: {
64 id: number
65 uuid: string
66 name: string
67 displayName: string
68 url: string
b64c950a 69 host: string
457bb213 70 avatar?: Avatar
b64c950a 71 }
aff038cd 72
6e46de09
C
73 userHistory?: {
74 currentTime: number
75 }
76
191764f3
C
77 static buildClientUrl (videoUUID: string) {
78 return '/videos/watch/' + videoUUID
79 }
80
7ce44a74 81 constructor (hash: VideoServerModel, translations = {}) {
c5911fd3 82 const absoluteAPIUrl = getAbsoluteAPIUrl()
c6e0bfbf 83
d592e0a9 84 this.createdAt = new Date(hash.createdAt.toString())
2922e048 85 this.publishedAt = new Date(hash.publishedAt.toString())
df98563e 86 this.category = hash.category
df98563e 87 this.licence = hash.licence
df98563e 88 this.language = hash.language
2243730c 89 this.privacy = hash.privacy
2186386c
C
90 this.waitTranscoding = hash.waitTranscoding
91 this.state = hash.state
df98563e
C
92 this.description = hash.description
93 this.duration = hash.duration
11b8762f 94 this.durationLabel = durationToString(hash.duration)
df98563e 95 this.id = hash.id
0a6658fd 96 this.uuid = hash.uuid
df98563e 97 this.isLocal = hash.isLocal
df98563e 98 this.name = hash.name
df98563e 99 this.thumbnailPath = hash.thumbnailPath
c6e0bfbf 100 this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath
43f61d26 101 this.previewPath = hash.previewPath
c6e0bfbf 102 this.previewUrl = absoluteAPIUrl + hash.previewPath
d8755eed 103 this.embedPath = hash.embedPath
c6e0bfbf 104 this.embedUrl = absoluteAPIUrl + hash.embedPath
df98563e
C
105 this.views = hash.views
106 this.likes = hash.likes
107 this.dislikes = hash.dislikes
108 this.nsfw = hash.nsfw
b64c950a 109 this.account = hash.account
52d9f792 110 this.channel = hash.channel
4fd8aa32 111
22a16e36
C
112 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
113 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
d3e91a5f 114 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
52d9f792 115 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel)
7ce44a74
C
116
117 this.category.label = peertubeTranslate(this.category.label, translations)
118 this.licence.label = peertubeTranslate(this.licence.label, translations)
119 this.language.label = peertubeTranslate(this.language.label, translations)
120 this.privacy.label = peertubeTranslate(this.privacy.label, translations)
2186386c 121
bbe0f064 122 this.scheduledUpdate = hash.scheduledUpdate
830b4faf
C
123 this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null
124
2186386c 125 if (this.state) this.state.label = peertubeTranslate(this.state.label, translations)
191764f3
C
126
127 this.blacklisted = hash.blacklisted
128 this.blacklistedReason = hash.blacklistedReason
6e46de09
C
129
130 this.userHistory = hash.userHistory
c5a1ae50
C
131
132 this.playlistElement = hash.playlistElement
501bc6c2
C
133 }
134
0883b324
C
135 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
136 // Video is not NSFW, skip
137 if (this.nsfw === false) return false
138
139 // Return user setting if logged in
140 if (user) return user.nsfwPolicy !== 'display'
141
142 // Return default instance config
143 return serverConfig.instance.defaultNSFWPolicy !== 'display'
92fb909c 144 }
3a0fb65c
C
145
146 isRemovableBy (user: AuthUser) {
147 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO))
148 }
149
150 isBlackistableBy (user: AuthUser) {
151 return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
152 }
153
154 isUnblacklistableBy (user: AuthUser) {
155 return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true
156 }
157
158 isUpdatableBy (user: AuthUser) {
159 return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
160 }
501bc6c2 161}