diff options
Diffstat (limited to 'client/src/app/shared/video/video.model.ts')
-rw-r--r-- | client/src/app/shared/video/video.model.ts | 182 |
1 files changed, 0 insertions, 182 deletions
diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts deleted file mode 100644 index dc5f45626..000000000 --- a/client/src/app/shared/video/video.model.ts +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | import { User } from '../' | ||
2 | import { UserRight, Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared' | ||
3 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' | ||
4 | import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model' | ||
5 | import { durationToString, getAbsoluteAPIUrl } from '../misc/utils' | ||
6 | import { peertubeTranslate, ServerConfig } from '../../../../../shared/models' | ||
7 | import { Actor } from '@app/shared/actor/actor.model' | ||
8 | import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' | ||
9 | import { AuthUser } from '@app/core' | ||
10 | import { environment } from '../../../environments/environment' | ||
11 | |||
12 | export class Video implements VideoServerModel { | ||
13 | byVideoChannel: string | ||
14 | byAccount: string | ||
15 | |||
16 | accountAvatarUrl: string | ||
17 | videoChannelAvatarUrl: string | ||
18 | |||
19 | createdAt: Date | ||
20 | updatedAt: Date | ||
21 | publishedAt: Date | ||
22 | originallyPublishedAt: Date | string | ||
23 | category: VideoConstant<number> | ||
24 | licence: VideoConstant<number> | ||
25 | language: VideoConstant<string> | ||
26 | privacy: VideoConstant<VideoPrivacy> | ||
27 | description: string | ||
28 | duration: number | ||
29 | durationLabel: string | ||
30 | id: number | ||
31 | uuid: string | ||
32 | isLocal: boolean | ||
33 | name: string | ||
34 | serverHost: string | ||
35 | thumbnailPath: string | ||
36 | thumbnailUrl: string | ||
37 | |||
38 | previewPath: string | ||
39 | previewUrl: string | ||
40 | |||
41 | embedPath: string | ||
42 | embedUrl: string | ||
43 | |||
44 | url?: string | ||
45 | |||
46 | views: number | ||
47 | likes: number | ||
48 | dislikes: number | ||
49 | nsfw: boolean | ||
50 | |||
51 | originInstanceUrl: string | ||
52 | originInstanceHost: string | ||
53 | |||
54 | waitTranscoding?: boolean | ||
55 | state?: VideoConstant<VideoState> | ||
56 | scheduledUpdate?: VideoScheduleUpdate | ||
57 | blacklisted?: boolean | ||
58 | blockedReason?: string | ||
59 | |||
60 | account: { | ||
61 | id: number | ||
62 | name: string | ||
63 | displayName: string | ||
64 | url: string | ||
65 | host: string | ||
66 | avatar?: Avatar | ||
67 | } | ||
68 | |||
69 | channel: { | ||
70 | id: number | ||
71 | name: string | ||
72 | displayName: string | ||
73 | url: string | ||
74 | host: string | ||
75 | avatar?: Avatar | ||
76 | } | ||
77 | |||
78 | userHistory?: { | ||
79 | currentTime: number | ||
80 | } | ||
81 | |||
82 | static buildClientUrl (videoUUID: string) { | ||
83 | return '/videos/watch/' + videoUUID | ||
84 | } | ||
85 | |||
86 | constructor (hash: VideoServerModel, translations = {}) { | ||
87 | const absoluteAPIUrl = getAbsoluteAPIUrl() | ||
88 | |||
89 | this.createdAt = new Date(hash.createdAt.toString()) | ||
90 | this.publishedAt = new Date(hash.publishedAt.toString()) | ||
91 | this.category = hash.category | ||
92 | this.licence = hash.licence | ||
93 | this.language = hash.language | ||
94 | this.privacy = hash.privacy | ||
95 | this.waitTranscoding = hash.waitTranscoding | ||
96 | this.state = hash.state | ||
97 | this.description = hash.description | ||
98 | |||
99 | this.duration = hash.duration | ||
100 | this.durationLabel = durationToString(hash.duration) | ||
101 | |||
102 | this.id = hash.id | ||
103 | this.uuid = hash.uuid | ||
104 | |||
105 | this.isLocal = hash.isLocal | ||
106 | this.name = hash.name | ||
107 | |||
108 | this.thumbnailPath = hash.thumbnailPath | ||
109 | this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath) | ||
110 | |||
111 | this.previewPath = hash.previewPath | ||
112 | this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath) | ||
113 | |||
114 | this.embedPath = hash.embedPath | ||
115 | this.embedUrl = hash.embedUrl || (environment.embedUrl + hash.embedPath) | ||
116 | |||
117 | this.url = hash.url | ||
118 | |||
119 | this.views = hash.views | ||
120 | this.likes = hash.likes | ||
121 | this.dislikes = hash.dislikes | ||
122 | |||
123 | this.nsfw = hash.nsfw | ||
124 | |||
125 | this.account = hash.account | ||
126 | this.channel = hash.channel | ||
127 | |||
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) | ||
130 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | ||
131 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) | ||
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) | ||
137 | |||
138 | this.scheduledUpdate = hash.scheduledUpdate | ||
139 | this.originallyPublishedAt = hash.originallyPublishedAt ? new Date(hash.originallyPublishedAt.toString()) : null | ||
140 | |||
141 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) | ||
142 | |||
143 | this.blacklisted = hash.blacklisted | ||
144 | this.blockedReason = hash.blacklistedReason | ||
145 | |||
146 | this.userHistory = hash.userHistory | ||
147 | |||
148 | this.originInstanceHost = this.account.host | ||
149 | this.originInstanceUrl = 'https://' + this.originInstanceHost | ||
150 | } | ||
151 | |||
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' | ||
161 | } | ||
162 | |||
163 | isRemovableBy (user: AuthUser) { | ||
164 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) | ||
165 | } | ||
166 | |||
167 | isBlockableBy (user: AuthUser) { | ||
168 | return this.blacklisted !== true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | ||
169 | } | ||
170 | |||
171 | isUnblockableBy (user: AuthUser) { | ||
172 | return this.blacklisted === true && user && user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) === true | ||
173 | } | ||
174 | |||
175 | isUpdatableBy (user: AuthUser) { | ||
176 | return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO)) | ||
177 | } | ||
178 | |||
179 | canBeDuplicatedBy (user: AuthUser) { | ||
180 | return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES) | ||
181 | } | ||
182 | } | ||