diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a43abbc09..d3fed338a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -2,7 +2,7 @@ import * as Bluebird from 'bluebird' | |||
2 | import { remove } from 'fs-extra' | 2 | import { remove } from 'fs-extra' |
3 | import { maxBy, minBy, pick } from 'lodash' | 3 | import { maxBy, minBy, pick } from 'lodash' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' | 5 | import { FindOptions, Includeable, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
6 | import { | 6 | import { |
7 | AllowNull, | 7 | AllowNull, |
8 | BeforeDestroy, | 8 | BeforeDestroy, |
@@ -190,26 +190,26 @@ export type AvailableForListIDsOptions = { | |||
190 | attributes: [ 'id', 'url', 'uuid', 'remote' ] | 190 | attributes: [ 'id', 'url', 'uuid', 'remote' ] |
191 | }, | 191 | }, |
192 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { | 192 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { |
193 | const query: FindOptions = { | 193 | const include: Includeable[] = [ |
194 | include: [ | 194 | { |
195 | { | 195 | model: VideoChannelModel.scope({ |
196 | model: VideoChannelModel.scope({ | 196 | method: [ |
197 | method: [ | 197 | VideoChannelScopeNames.SUMMARY, { |
198 | VideoChannelScopeNames.SUMMARY, { | 198 | withAccount: true, |
199 | withAccount: true, | 199 | withAccountBlockerIds: options.withAccountBlockerIds |
200 | withAccountBlockerIds: options.withAccountBlockerIds | 200 | } as SummaryOptions |
201 | } as SummaryOptions | 201 | ] |
202 | ] | 202 | }), |
203 | }), | 203 | required: true |
204 | required: true | 204 | }, |
205 | }, | 205 | { |
206 | { | 206 | attributes: [ 'type', 'filename' ], |
207 | attributes: [ 'type', 'filename' ], | 207 | model: ThumbnailModel, |
208 | model: ThumbnailModel, | 208 | required: false |
209 | required: false | 209 | } |
210 | } | 210 | ] |
211 | ] | 211 | |
212 | } | 212 | const query: FindOptions = {} |
213 | 213 | ||
214 | if (options.ids) { | 214 | if (options.ids) { |
215 | query.where = { | 215 | query.where = { |
@@ -220,14 +220,14 @@ export type AvailableForListIDsOptions = { | |||
220 | } | 220 | } |
221 | 221 | ||
222 | if (options.withFiles === true) { | 222 | if (options.withFiles === true) { |
223 | query.include.push({ | 223 | include.push({ |
224 | model: VideoFileModel, | 224 | model: VideoFileModel, |
225 | required: true | 225 | required: true |
226 | }) | 226 | }) |
227 | } | 227 | } |
228 | 228 | ||
229 | if (options.videoPlaylistId) { | 229 | if (options.videoPlaylistId) { |
230 | query.include.push({ | 230 | include.push({ |
231 | model: VideoPlaylistElementModel.unscoped(), | 231 | model: VideoPlaylistElementModel.unscoped(), |
232 | required: true, | 232 | required: true, |
233 | where: { | 233 | where: { |
@@ -236,6 +236,8 @@ export type AvailableForListIDsOptions = { | |||
236 | }) | 236 | }) |
237 | } | 237 | } |
238 | 238 | ||
239 | query.include = include | ||
240 | |||
239 | return query | 241 | return query |
240 | }, | 242 | }, |
241 | [ScopeNames.WITH_THUMBNAILS]: { | 243 | [ScopeNames.WITH_THUMBNAILS]: { |
@@ -477,7 +479,7 @@ export type AvailableForListIDsOptions = { | |||
477 | } | 479 | } |
478 | ] | 480 | ] |
479 | }) | 481 | }) |
480 | export class VideoModel extends Model<VideoModel> { | 482 | export class VideoModel extends Model { |
481 | 483 | ||
482 | @AllowNull(false) | 484 | @AllowNull(false) |
483 | @Default(DataType.UUIDV4) | 485 | @Default(DataType.UUIDV4) |
@@ -860,7 +862,7 @@ export class VideoModel extends Model<VideoModel> { | |||
860 | return undefined | 862 | return undefined |
861 | } | 863 | } |
862 | 864 | ||
863 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { | 865 | static listLocal (): Promise<MVideoWithAllFiles[]> { |
864 | const query = { | 866 | const query = { |
865 | where: { | 867 | where: { |
866 | remote: false | 868 | remote: false |
@@ -988,7 +990,7 @@ export class VideoModel extends Model<VideoModel> { | |||
988 | }) | 990 | }) |
989 | } | 991 | } |
990 | 992 | ||
991 | static listPublishedLiveIds () { | 993 | static async listPublishedLiveIds () { |
992 | const options = { | 994 | const options = { |
993 | attributes: [ 'id' ], | 995 | attributes: [ 'id' ], |
994 | where: { | 996 | where: { |
@@ -997,8 +999,9 @@ export class VideoModel extends Model<VideoModel> { | |||
997 | } | 999 | } |
998 | } | 1000 | } |
999 | 1001 | ||
1000 | return VideoModel.findAll(options) | 1002 | const result = await VideoModel.findAll(options) |
1001 | .map(v => v.id) | 1003 | |
1004 | return result.map(v => v.id) | ||
1002 | } | 1005 | } |
1003 | 1006 | ||
1004 | static listUserVideosForApi ( | 1007 | static listUserVideosForApi ( |
@@ -1214,7 +1217,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1214 | return VideoModel.count(options) | 1217 | return VideoModel.count(options) |
1215 | } | 1218 | } |
1216 | 1219 | ||
1217 | static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> { | 1220 | static load (id: number | string, t?: Transaction): Promise<MVideoThumbnail> { |
1218 | const where = buildWhereIdOrUUID(id) | 1221 | const where = buildWhereIdOrUUID(id) |
1219 | const options = { | 1222 | const options = { |
1220 | where, | 1223 | where, |
@@ -1224,7 +1227,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1224 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1227 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1225 | } | 1228 | } |
1226 | 1229 | ||
1227 | static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> { | 1230 | static loadWithBlacklist (id: number | string, t?: Transaction): Promise<MVideoThumbnailBlacklist> { |
1228 | const where = buildWhereIdOrUUID(id) | 1231 | const where = buildWhereIdOrUUID(id) |
1229 | const options = { | 1232 | const options = { |
1230 | where, | 1233 | where, |
@@ -1237,7 +1240,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1237 | ]).findOne(options) | 1240 | ]).findOne(options) |
1238 | } | 1241 | } |
1239 | 1242 | ||
1240 | static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> { | 1243 | static loadImmutableAttributes (id: number | string, t?: Transaction): Promise<MVideoImmutable> { |
1241 | const fun = () => { | 1244 | const fun = () => { |
1242 | const query = { | 1245 | const query = { |
1243 | where: buildWhereIdOrUUID(id), | 1246 | where: buildWhereIdOrUUID(id), |
@@ -1255,7 +1258,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1255 | }) | 1258 | }) |
1256 | } | 1259 | } |
1257 | 1260 | ||
1258 | static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> { | 1261 | static loadWithRights (id: number | string, t?: Transaction): Promise<MVideoWithRights> { |
1259 | const where = buildWhereIdOrUUID(id) | 1262 | const where = buildWhereIdOrUUID(id) |
1260 | const options = { | 1263 | const options = { |
1261 | where, | 1264 | where, |
@@ -1269,7 +1272,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1269 | ]).findOne(options) | 1272 | ]).findOne(options) |
1270 | } | 1273 | } |
1271 | 1274 | ||
1272 | static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> { | 1275 | static loadOnlyId (id: number | string, t?: Transaction): Promise<MVideoIdThumbnail> { |
1273 | const where = buildWhereIdOrUUID(id) | 1276 | const where = buildWhereIdOrUUID(id) |
1274 | 1277 | ||
1275 | const options = { | 1278 | const options = { |
@@ -1281,7 +1284,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1281 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1284 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1282 | } | 1285 | } |
1283 | 1286 | ||
1284 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> { | 1287 | static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Promise<MVideoWithAllFiles> { |
1285 | const where = buildWhereIdOrUUID(id) | 1288 | const where = buildWhereIdOrUUID(id) |
1286 | 1289 | ||
1287 | const query = { | 1290 | const query = { |
@@ -1297,7 +1300,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1297 | ]).findOne(query) | 1300 | ]).findOne(query) |
1298 | } | 1301 | } |
1299 | 1302 | ||
1300 | static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> { | 1303 | static loadByUUID (uuid: string): Promise<MVideoThumbnail> { |
1301 | const options = { | 1304 | const options = { |
1302 | where: { | 1305 | where: { |
1303 | uuid | 1306 | uuid |
@@ -1307,7 +1310,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1307 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) | 1310 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) |
1308 | } | 1311 | } |
1309 | 1312 | ||
1310 | static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> { | 1313 | static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoThumbnail> { |
1311 | const query: FindOptions = { | 1314 | const query: FindOptions = { |
1312 | where: { | 1315 | where: { |
1313 | url | 1316 | url |
@@ -1318,7 +1321,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1318 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1321 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1319 | } | 1322 | } |
1320 | 1323 | ||
1321 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> { | 1324 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Promise<MVideoImmutable> { |
1322 | const fun = () => { | 1325 | const fun = () => { |
1323 | const query: FindOptions = { | 1326 | const query: FindOptions = { |
1324 | where: { | 1327 | where: { |
@@ -1338,7 +1341,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1338 | }) | 1341 | }) |
1339 | } | 1342 | } |
1340 | 1343 | ||
1341 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { | 1344 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> { |
1342 | const query: FindOptions = { | 1345 | const query: FindOptions = { |
1343 | where: { | 1346 | where: { |
1344 | url | 1347 | url |
@@ -1355,7 +1358,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1355 | ]).findOne(query) | 1358 | ]).findOne(query) |
1356 | } | 1359 | } |
1357 | 1360 | ||
1358 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> { | 1361 | static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Promise<MVideoFullLight> { |
1359 | const where = buildWhereIdOrUUID(id) | 1362 | const where = buildWhereIdOrUUID(id) |
1360 | 1363 | ||
1361 | const options = { | 1364 | const options = { |
@@ -1388,7 +1391,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1388 | id: number | string | 1391 | id: number | string |
1389 | t?: Transaction | 1392 | t?: Transaction |
1390 | userId?: number | 1393 | userId?: number |
1391 | }): Bluebird<MVideoDetails> { | 1394 | }): Promise<MVideoDetails> { |
1392 | const { id, t, userId } = parameters | 1395 | const { id, t, userId } = parameters |
1393 | const where = buildWhereIdOrUUID(id) | 1396 | const where = buildWhereIdOrUUID(id) |
1394 | 1397 | ||
@@ -1487,7 +1490,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1487 | return VideoModel.update({ support: videoChannel.support }, options) | 1490 | return VideoModel.update({ support: videoChannel.support }, options) |
1488 | } | 1491 | } |
1489 | 1492 | ||
1490 | static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> { | 1493 | static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> { |
1491 | const query = { | 1494 | const query = { |
1492 | attributes: [ 'id' ], | 1495 | attributes: [ 'id' ], |
1493 | where: { | 1496 | where: { |