diff options
Diffstat (limited to 'server/models/video/video-playlist-element.ts')
-rw-r--r-- | server/models/video/video-playlist-element.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 901113161..80ca22a18 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -21,12 +21,16 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | |||
21 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' | 21 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' |
22 | import * as validator from 'validator' | 22 | import * as validator from 'validator' |
23 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 23 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
24 | import { UserModel } from '../account/user' | ||
25 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' | 24 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' |
26 | import { AccountModel } from '../account/account' | 25 | import { AccountModel } from '../account/account' |
27 | import { VideoPrivacy } from '../../../shared/models/videos' | 26 | import { VideoPrivacy } from '../../../shared/models/videos' |
28 | import * as Bluebird from 'bluebird' | 27 | import * as Bluebird from 'bluebird' |
29 | import { MVideoPlaylistAP, MVideoPlaylistElement, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' | 28 | import { |
29 | MVideoPlaylistElement, | ||
30 | MVideoPlaylistElementAP, | ||
31 | MVideoPlaylistElementFormattable, | ||
32 | MVideoPlaylistVideoThumbnail | ||
33 | } from '@server/typings/models/video/video-playlist-element' | ||
30 | import { MUserAccountId } from '@server/typings/models' | 34 | import { MUserAccountId } from '@server/typings/models' |
31 | 35 | ||
32 | @Table({ | 36 | @Table({ |
@@ -180,7 +184,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
180 | return VideoPlaylistElementModel.findByPk(playlistElementId) | 184 | return VideoPlaylistElementModel.findByPk(playlistElementId) |
181 | } | 185 | } |
182 | 186 | ||
183 | static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistAP> { | 187 | static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistElementAP> { |
184 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } | 188 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } |
185 | const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } | 189 | const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } |
186 | 190 | ||
@@ -293,7 +297,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
293 | return VideoPlaylistElementModel.increment({ position: by }, query) | 297 | return VideoPlaylistElementModel.increment({ position: by }, query) |
294 | } | 298 | } |
295 | 299 | ||
296 | getType (displayNSFW?: boolean, accountId?: number) { | 300 | getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { |
297 | const video = this.Video | 301 | const video = this.Video |
298 | 302 | ||
299 | if (!video) return VideoPlaylistElementType.DELETED | 303 | if (!video) return VideoPlaylistElementType.DELETED |
@@ -309,14 +313,17 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
309 | return VideoPlaylistElementType.REGULAR | 313 | return VideoPlaylistElementType.REGULAR |
310 | } | 314 | } |
311 | 315 | ||
312 | getVideoElement (displayNSFW?: boolean, accountId?: number) { | 316 | getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) { |
313 | if (!this.Video) return null | 317 | if (!this.Video) return null |
314 | if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null | 318 | if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null |
315 | 319 | ||
316 | return this.Video.toFormattedJSON() | 320 | return this.Video.toFormattedJSON() |
317 | } | 321 | } |
318 | 322 | ||
319 | toFormattedJSON (options: { displayNSFW?: boolean, accountId?: number } = {}): VideoPlaylistElement { | 323 | toFormattedJSON ( |
324 | this: MVideoPlaylistElementFormattable, | ||
325 | options: { displayNSFW?: boolean, accountId?: number } = {} | ||
326 | ): VideoPlaylistElement { | ||
320 | return { | 327 | return { |
321 | id: this.id, | 328 | id: this.id, |
322 | position: this.position, | 329 | position: this.position, |