]>
Commit | Line | Data |
---|---|---|
202f6b6c | 1 | import { User } from '../' |
bfbd9128 | 2 | import { UserRight, Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared' |
b64c950a | 3 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
40e87e9e | 4 | import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model' |
11b8762f | 5 | import { durationToString, getAbsoluteAPIUrl } from '../misc/utils' |
3dfa8494 | 6 | import { peertubeTranslate, ServerConfig } from '../../../../../shared/models' |
d3e91a5f | 7 | import { Actor } from '@app/shared/actor/actor.model' |
bbe0f064 | 8 | import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' |
3a0fb65c | 9 | import { AuthUser } from '@app/core' |
92fb909c | 10 | |
69f616ab | 11 | export 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 | |
c910f667 C |
45 | originInstanceUrl: string |
46 | originInstanceHost: string | |
47 | ||
2186386c C |
48 | waitTranscoding?: boolean |
49 | state?: VideoConstant<VideoState> | |
bbe0f064 | 50 | scheduledUpdate?: VideoScheduleUpdate |
191764f3 C |
51 | blacklisted?: boolean |
52 | blacklistedReason?: string | |
2186386c | 53 | |
b64c950a | 54 | account: { |
03e12d7c | 55 | id: number |
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 | |
0f320037 C |
65 | name: string |
66 | displayName: string | |
67 | url: string | |
b64c950a | 68 | host: string |
457bb213 | 69 | avatar?: Avatar |
b64c950a | 70 | } |
aff038cd | 71 | |
6e46de09 C |
72 | userHistory?: { |
73 | currentTime: number | |
74 | } | |
75 | ||
191764f3 C |
76 | static buildClientUrl (videoUUID: string) { |
77 | return '/videos/watch/' + videoUUID | |
78 | } | |
79 | ||
7ce44a74 | 80 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 81 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 82 | |
d592e0a9 | 83 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 84 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 85 | this.category = hash.category |
df98563e | 86 | this.licence = hash.licence |
df98563e | 87 | this.language = hash.language |
2243730c | 88 | this.privacy = hash.privacy |
2186386c C |
89 | this.waitTranscoding = hash.waitTranscoding |
90 | this.state = hash.state | |
df98563e | 91 | this.description = hash.description |
c910f667 | 92 | |
df98563e | 93 | this.duration = hash.duration |
11b8762f | 94 | this.durationLabel = durationToString(hash.duration) |
c910f667 | 95 | |
df98563e | 96 | this.id = hash.id |
0a6658fd | 97 | this.uuid = hash.uuid |
c910f667 | 98 | |
df98563e | 99 | this.isLocal = hash.isLocal |
df98563e | 100 | this.name = hash.name |
c910f667 | 101 | |
df98563e | 102 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 103 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
c910f667 | 104 | |
43f61d26 | 105 | this.previewPath = hash.previewPath |
c6e0bfbf | 106 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
c910f667 | 107 | |
d8755eed | 108 | this.embedPath = hash.embedPath |
c6e0bfbf | 109 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
c910f667 | 110 | |
df98563e C |
111 | this.views = hash.views |
112 | this.likes = hash.likes | |
113 | this.dislikes = hash.dislikes | |
c910f667 | 114 | |
df98563e | 115 | this.nsfw = hash.nsfw |
c910f667 | 116 | |
b64c950a | 117 | this.account = hash.account |
52d9f792 | 118 | this.channel = hash.channel |
4fd8aa32 | 119 | |
22a16e36 C |
120 | this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
121 | this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) | |
d3e91a5f | 122 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) |
52d9f792 | 123 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) |
7ce44a74 C |
124 | |
125 | this.category.label = peertubeTranslate(this.category.label, translations) | |
126 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
127 | this.language.label = peertubeTranslate(this.language.label, translations) | |
128 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 129 | |
bbe0f064 | 130 | this.scheduledUpdate = hash.scheduledUpdate |
830b4faf C |
131 | this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null |
132 | ||
2186386c | 133 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) |
191764f3 C |
134 | |
135 | this.blacklisted = hash.blacklisted | |
136 | this.blacklistedReason = hash.blacklistedReason | |
6e46de09 C |
137 | |
138 | this.userHistory = hash.userHistory | |
c910f667 C |
139 | |
140 | this.originInstanceHost = this.account.host | |
141 | this.originInstanceUrl = 'https://' + this.originInstanceHost | |
501bc6c2 C |
142 | } |
143 | ||
0883b324 C |
144 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
145 | // Video is not NSFW, skip | |
146 | if (this.nsfw === false) return false | |
147 | ||
148 | // Return user setting if logged in | |
149 | if (user) return user.nsfwPolicy !== 'display' | |
150 | ||
151 | // Return default instance config | |
152 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 153 | } |
3a0fb65c C |
154 | |
155 | isRemovableBy (user: AuthUser) { | |
156 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | |
157 | } | |
158 | ||
159 | isBlackistableBy (user: AuthUser) { | |
160 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | |
161 | } | |
162 | ||
163 | isUnblacklistableBy (user: AuthUser) { | |
164 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | |
165 | } | |
166 | ||
167 | isUpdatableBy (user: AuthUser) { | |
168 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | |
169 | } | |
b764380a C |
170 | |
171 | canBeDuplicatedBy (user: AuthUser) { | |
172 | return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) | |
173 | } | |
501bc6c2 | 174 | } |