]>
Commit | Line | Data |
---|---|---|
3a0fb65c | 1 | import { AuthUser } from '@app/core' |
67ed6552 | 2 | import { User } from '@app/core/users/user.model' |
72493e44 | 3 | import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
bd45d503 | 4 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
67ed6552 C |
5 | import { |
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 | 15 | import { Actor } from '../account/actor.model' |
92fb909c | 16 | |
69f616ab | 17 | export 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 | ||
7294aab0 C |
87 | pluginData?: any |
88 | ||
191764f3 C |
89 | static buildClientUrl (videoUUID: string) { |
90 | return '/videos/watch/' + videoUUID | |
91 | } | |
92 | ||
7ce44a74 | 93 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 94 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 95 | |
d592e0a9 | 96 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 97 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 98 | this.category = hash.category |
df98563e | 99 | this.licence = hash.licence |
df98563e | 100 | this.language = hash.language |
2243730c | 101 | this.privacy = hash.privacy |
2186386c C |
102 | this.waitTranscoding = hash.waitTranscoding |
103 | this.state = hash.state | |
df98563e | 104 | this.description = hash.description |
c910f667 | 105 | |
df98563e | 106 | this.duration = hash.duration |
11b8762f | 107 | this.durationLabel = durationToString(hash.duration) |
c910f667 | 108 | |
df98563e | 109 | this.id = hash.id |
0a6658fd | 110 | this.uuid = hash.uuid |
c910f667 | 111 | |
df98563e | 112 | this.isLocal = hash.isLocal |
df98563e | 113 | this.name = hash.name |
c910f667 | 114 | |
df98563e | 115 | this.thumbnailPath = hash.thumbnailPath |
5fb2e288 | 116 | this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) |
c910f667 | 117 | |
43f61d26 | 118 | this.previewPath = hash.previewPath |
5fb2e288 | 119 | this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath) |
c910f667 | 120 | |
d8755eed | 121 | this.embedPath = hash.embedPath |
72493e44 | 122 | this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath) |
5fb2e288 C |
123 | |
124 | this.url = hash.url | |
c910f667 | 125 | |
df98563e C |
126 | this.views = hash.views |
127 | this.likes = hash.likes | |
128 | this.dislikes = hash.dislikes | |
c910f667 | 129 | |
df98563e | 130 | this.nsfw = hash.nsfw |
c910f667 | 131 | |
b64c950a | 132 | this.account = hash.account |
52d9f792 | 133 | this.channel = hash.channel |
4fd8aa32 | 134 | |
22a16e36 C |
135 | this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
136 | this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) | |
d3e91a5f | 137 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) |
52d9f792 | 138 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) |
7ce44a74 C |
139 | |
140 | this.category.label = peertubeTranslate(this.category.label, translations) | |
141 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
142 | this.language.label = peertubeTranslate(this.language.label, translations) | |
143 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 144 | |
bbe0f064 | 145 | this.scheduledUpdate = hash.scheduledUpdate |
830b4faf C |
146 | this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null |
147 | ||
2186386c | 148 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) |
191764f3 C |
149 | |
150 | this.blacklisted = hash.blacklisted | |
5baee5fc | 151 | this.blockedReason = hash.blacklistedReason |
6e46de09 C |
152 | |
153 | this.userHistory = hash.userHistory | |
c910f667 C |
154 | |
155 | this.originInstanceHost = this.account.host | |
156 | this.originInstanceUrl = 'https://' + this.originInstanceHost | |
7294aab0 C |
157 | |
158 | this.pluginData = hash.pluginData | |
501bc6c2 C |
159 | } |
160 | ||
0883b324 C |
161 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
162 | // Video is not NSFW, skip | |
163 | if (this.nsfw === false) return false | |
164 | ||
165 | // Return user setting if logged in | |
166 | if (user) return user.nsfwPolicy !== 'display' | |
167 | ||
168 | // Return default instance config | |
169 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 170 | } |
3a0fb65c C |
171 | |
172 | isRemovableBy (user: AuthUser) { | |
173 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | |
174 | } | |
175 | ||
5baee5fc | 176 | isBlockableBy (user: AuthUser) { |
3487330d | 177 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true |
3a0fb65c C |
178 | } |
179 | ||
5baee5fc | 180 | isUnblockableBy (user: AuthUser) { |
3487330d | 181 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true |
3a0fb65c C |
182 | } |
183 | ||
184 | isUpdatableBy (user: AuthUser) { | |
185 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | |
186 | } | |
b764380a C |
187 | |
188 | canBeDuplicatedBy (user: AuthUser) { | |
189 | return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) | |
190 | } | |
501bc6c2 | 191 | } |