diff options
Diffstat (limited to 'server/models/video/video-playlist-element.ts')
-rw-r--r-- | server/models/video/video-playlist-element.ts | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index d357766e9..d2d7e2740 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' | ||
1 | import { | 2 | import { |
2 | AllowNull, | 3 | AllowNull, |
3 | BelongsTo, | 4 | BelongsTo, |
@@ -13,18 +14,8 @@ import { | |||
13 | Table, | 14 | Table, |
14 | UpdatedAt | 15 | UpdatedAt |
15 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
16 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
17 | import { VideoPlaylistModel } from './video-playlist' | ||
18 | import { getSort, throwIfNotValid } from '../utils' | ||
19 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
20 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | ||
21 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' | ||
22 | import validator from 'validator' | 17 | import validator from 'validator' |
23 | import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 18 | import { MUserAccountId } from '@server/types/models' |
24 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' | ||
25 | import { AccountModel } from '../account/account' | ||
26 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
27 | import * as Bluebird from 'bluebird' | ||
28 | import { | 19 | import { |
29 | MVideoPlaylistElement, | 20 | MVideoPlaylistElement, |
30 | MVideoPlaylistElementAP, | 21 | MVideoPlaylistElementAP, |
@@ -32,7 +23,15 @@ import { | |||
32 | MVideoPlaylistElementVideoUrlPlaylistPrivacy, | 23 | MVideoPlaylistElementVideoUrlPlaylistPrivacy, |
33 | MVideoPlaylistVideoThumbnail | 24 | MVideoPlaylistVideoThumbnail |
34 | } from '@server/types/models/video/video-playlist-element' | 25 | } from '@server/types/models/video/video-playlist-element' |
35 | import { MUserAccountId } from '@server/types/models' | 26 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' |
27 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
28 | import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' | ||
29 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
30 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | ||
31 | import { AccountModel } from '../account/account' | ||
32 | import { getSort, throwIfNotValid } from '../utils' | ||
33 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' | ||
34 | import { VideoPlaylistModel } from './video-playlist' | ||
36 | 35 | ||
37 | @Table({ | 36 | @Table({ |
38 | tableName: 'videoPlaylistElement', | 37 | tableName: 'videoPlaylistElement', |
@@ -49,7 +48,7 @@ import { MUserAccountId } from '@server/types/models' | |||
49 | } | 48 | } |
50 | ] | 49 | ] |
51 | }) | 50 | }) |
52 | export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> { | 51 | export class VideoPlaylistElementModel extends Model { |
53 | @CreatedAt | 52 | @CreatedAt |
54 | createdAt: Date | 53 | createdAt: Date |
55 | 54 | ||
@@ -166,7 +165,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
166 | ]).then(([ total, data ]) => ({ total, data })) | 165 | ]).then(([ total, data ]) => ({ total, data })) |
167 | } | 166 | } |
168 | 167 | ||
169 | static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number): Bluebird<MVideoPlaylistElement> { | 168 | static loadByPlaylistAndVideo (videoPlaylistId: number, videoId: number): Promise<MVideoPlaylistElement> { |
170 | const query = { | 169 | const query = { |
171 | where: { | 170 | where: { |
172 | videoPlaylistId, | 171 | videoPlaylistId, |
@@ -177,14 +176,14 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
177 | return VideoPlaylistElementModel.findOne(query) | 176 | return VideoPlaylistElementModel.findOne(query) |
178 | } | 177 | } |
179 | 178 | ||
180 | static loadById (playlistElementId: number | string): Bluebird<MVideoPlaylistElement> { | 179 | static loadById (playlistElementId: number | string): Promise<MVideoPlaylistElement> { |
181 | return VideoPlaylistElementModel.findByPk(playlistElementId) | 180 | return VideoPlaylistElementModel.findByPk(playlistElementId) |
182 | } | 181 | } |
183 | 182 | ||
184 | static loadByPlaylistAndElementIdForAP ( | 183 | static loadByPlaylistAndElementIdForAP ( |
185 | playlistId: number | string, | 184 | playlistId: number | string, |
186 | playlistElementId: number | 185 | playlistElementId: number |
187 | ): Bluebird<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { | 186 | ): Promise<MVideoPlaylistElementVideoUrlPlaylistPrivacy> { |
188 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } | 187 | const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } |
189 | 188 | ||
190 | const query = { | 189 | const query = { |
@@ -226,7 +225,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
226 | }) | 225 | }) |
227 | } | 226 | } |
228 | 227 | ||
229 | static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Bluebird<MVideoPlaylistVideoThumbnail> { | 228 | static loadFirstElementWithVideoThumbnail (videoPlaylistId: number): Promise<MVideoPlaylistVideoThumbnail> { |
230 | const query = { | 229 | const query = { |
231 | order: getSort('position'), | 230 | order: getSort('position'), |
232 | where: { | 231 | where: { |