aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-31 16:56:52 +0100
committerChocobozzz <me@florianbigard.com>2020-02-03 08:31:02 +0100
commita15871560f80e07386c1dabb8370cd2664ecfd1f (patch)
tree44440e140c9e43b0d7f97ade777a76e649e0553d /server/models/video/video.ts
parenta22046d166805222ca76060e471b6cb3d419a32d (diff)
downloadPeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.gz
PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.tar.zst
PeerTube-a15871560f80e07386c1dabb8370cd2664ecfd1f.zip
Move to eslintcontain
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts165
1 files changed, 82 insertions, 83 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 1a924e6c9..1ec8d717e 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -187,7 +187,7 @@ export type AvailableForListIDsOptions = {
187} 187}
188 188
189@Scopes(() => ({ 189@Scopes(() => ({
190 [ ScopeNames.FOR_API ]: (options: ForAPIOptions) => { 190 [ScopeNames.FOR_API]: (options: ForAPIOptions) => {
191 const query: FindOptions = { 191 const query: FindOptions = {
192 include: [ 192 include: [
193 { 193 {
@@ -212,7 +212,7 @@ export type AvailableForListIDsOptions = {
212 if (options.ids) { 212 if (options.ids) {
213 query.where = { 213 query.where = {
214 id: { 214 id: {
215 [ Op.in ]: options.ids 215 [Op.in]: options.ids
216 } 216 }
217 } 217 }
218 } 218 }
@@ -236,7 +236,7 @@ export type AvailableForListIDsOptions = {
236 236
237 return query 237 return query
238 }, 238 },
239 [ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => { 239 [ScopeNames.AVAILABLE_FOR_LIST_IDS]: (options: AvailableForListIDsOptions) => {
240 const whereAnd = options.baseWhere ? [].concat(options.baseWhere) : [] 240 const whereAnd = options.baseWhere ? [].concat(options.baseWhere) : []
241 241
242 const query: FindOptions = { 242 const query: FindOptions = {
@@ -247,11 +247,11 @@ export type AvailableForListIDsOptions = {
247 const attributesType = options.attributesType || 'id' 247 const attributesType = options.attributesType || 'id'
248 248
249 if (attributesType === 'id') query.attributes = [ 'id' ] 249 if (attributesType === 'id') query.attributes = [ 'id' ]
250 else if (attributesType === 'none') query.attributes = [ ] 250 else if (attributesType === 'none') query.attributes = []
251 251
252 whereAnd.push({ 252 whereAnd.push({
253 id: { 253 id: {
254 [ Op.notIn ]: Sequelize.literal( 254 [Op.notIn]: Sequelize.literal(
255 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")' 255 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
256 ) 256 )
257 } 257 }
@@ -260,7 +260,7 @@ export type AvailableForListIDsOptions = {
260 if (options.serverAccountId) { 260 if (options.serverAccountId) {
261 whereAnd.push({ 261 whereAnd.push({
262 channelId: { 262 channelId: {
263 [ Op.notIn ]: Sequelize.literal( 263 [Op.notIn]: Sequelize.literal(
264 '(' + 264 '(' +
265 'SELECT id FROM "videoChannel" WHERE "accountId" IN (' + 265 'SELECT id FROM "videoChannel" WHERE "accountId" IN (' +
266 buildBlockedAccountSQL(options.serverAccountId, options.user ? options.user.Account.id : undefined) + 266 buildBlockedAccountSQL(options.serverAccountId, options.user ? options.user.Account.id : undefined) +
@@ -273,15 +273,14 @@ export type AvailableForListIDsOptions = {
273 273
274 // Only list public/published videos 274 // Only list public/published videos
275 if (!options.filter || options.filter !== 'all-local') { 275 if (!options.filter || options.filter !== 'all-local') {
276
277 const publishWhere = { 276 const publishWhere = {
278 // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding 277 // Always list published videos, or videos that are being transcoded but on which we don't want to wait for transcoding
279 [ Op.or ]: [ 278 [Op.or]: [
280 { 279 {
281 state: VideoState.PUBLISHED 280 state: VideoState.PUBLISHED
282 }, 281 },
283 { 282 {
284 [ Op.and ]: { 283 [Op.and]: {
285 state: VideoState.TO_TRANSCODE, 284 state: VideoState.TO_TRANSCODE,
286 waitTranscoding: false 285 waitTranscoding: false
287 } 286 }
@@ -368,7 +367,7 @@ export type AvailableForListIDsOptions = {
368 [Op.or]: [ 367 [Op.or]: [
369 { 368 {
370 id: { 369 id: {
371 [ Op.in ]: Sequelize.literal( 370 [Op.in]: Sequelize.literal(
372 '(' + 371 '(' +
373 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' + 372 'SELECT "videoShare"."videoId" AS "id" FROM "videoShare" ' +
374 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + 373 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
@@ -379,7 +378,7 @@ export type AvailableForListIDsOptions = {
379 }, 378 },
380 { 379 {
381 id: { 380 id: {
382 [ Op.in ]: Sequelize.literal( 381 [Op.in]: Sequelize.literal(
383 '(' + 382 '(' +
384 'SELECT "video"."id" AS "id" FROM "video" ' + 383 'SELECT "video"."id" AS "id" FROM "video" ' +
385 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + 384 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
@@ -399,7 +398,7 @@ export type AvailableForListIDsOptions = {
399 if (options.withFiles === true) { 398 if (options.withFiles === true) {
400 whereAnd.push({ 399 whereAnd.push({
401 id: { 400 id: {
402 [ Op.in ]: Sequelize.literal( 401 [Op.in]: Sequelize.literal(
403 '(SELECT "videoId" FROM "videoFile")' 402 '(SELECT "videoId" FROM "videoFile")'
404 ) 403 )
405 } 404 }
@@ -413,7 +412,7 @@ export type AvailableForListIDsOptions = {
413 412
414 whereAnd.push({ 413 whereAnd.push({
415 id: { 414 id: {
416 [ Op.in ]: Sequelize.literal( 415 [Op.in]: Sequelize.literal(
417 '(' + 416 '(' +
418 'SELECT "videoId" FROM "videoTag" ' + 417 'SELECT "videoId" FROM "videoTag" ' +
419 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + 418 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
@@ -429,7 +428,7 @@ export type AvailableForListIDsOptions = {
429 428
430 whereAnd.push({ 429 whereAnd.push({
431 id: { 430 id: {
432 [ Op.in ]: Sequelize.literal( 431 [Op.in]: Sequelize.literal(
433 '(' + 432 '(' +
434 'SELECT "videoId" FROM "videoTag" ' + 433 'SELECT "videoId" FROM "videoTag" ' +
435 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' + 434 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
@@ -449,7 +448,7 @@ export type AvailableForListIDsOptions = {
449 if (options.categoryOneOf) { 448 if (options.categoryOneOf) {
450 whereAnd.push({ 449 whereAnd.push({
451 category: { 450 category: {
452 [ Op.or ]: options.categoryOneOf 451 [Op.or]: options.categoryOneOf
453 } 452 }
454 }) 453 })
455 } 454 }
@@ -457,7 +456,7 @@ export type AvailableForListIDsOptions = {
457 if (options.licenceOneOf) { 456 if (options.licenceOneOf) {
458 whereAnd.push({ 457 whereAnd.push({
459 licence: { 458 licence: {
460 [ Op.or ]: options.licenceOneOf 459 [Op.or]: options.licenceOneOf
461 } 460 }
462 }) 461 })
463 } 462 }
@@ -472,12 +471,12 @@ export type AvailableForListIDsOptions = {
472 [Op.or]: [ 471 [Op.or]: [
473 { 472 {
474 language: { 473 language: {
475 [ Op.or ]: videoLanguages 474 [Op.or]: videoLanguages
476 } 475 }
477 }, 476 },
478 { 477 {
479 id: { 478 id: {
480 [ Op.in ]: Sequelize.literal( 479 [Op.in]: Sequelize.literal(
481 '(' + 480 '(' +
482 'SELECT "videoId" FROM "videoCaption" ' + 481 'SELECT "videoId" FROM "videoCaption" ' +
483 'WHERE "language" IN (' + createSafeIn(VideoModel, options.languageOneOf) + ') ' + 482 'WHERE "language" IN (' + createSafeIn(VideoModel, options.languageOneOf) + ') ' +
@@ -511,12 +510,12 @@ export type AvailableForListIDsOptions = {
511 } 510 }
512 511
513 query.where = { 512 query.where = {
514 [ Op.and ]: whereAnd 513 [Op.and]: whereAnd
515 } 514 }
516 515
517 return query 516 return query
518 }, 517 },
519 [ ScopeNames.WITH_THUMBNAILS ]: { 518 [ScopeNames.WITH_THUMBNAILS]: {
520 include: [ 519 include: [
521 { 520 {
522 model: ThumbnailModel, 521 model: ThumbnailModel,
@@ -524,7 +523,7 @@ export type AvailableForListIDsOptions = {
524 } 523 }
525 ] 524 ]
526 }, 525 },
527 [ ScopeNames.WITH_USER_ID ]: { 526 [ScopeNames.WITH_USER_ID]: {
528 include: [ 527 include: [
529 { 528 {
530 attributes: [ 'accountId' ], 529 attributes: [ 'accountId' ],
@@ -540,7 +539,7 @@ export type AvailableForListIDsOptions = {
540 } 539 }
541 ] 540 ]
542 }, 541 },
543 [ ScopeNames.WITH_ACCOUNT_DETAILS ]: { 542 [ScopeNames.WITH_ACCOUNT_DETAILS]: {
544 include: [ 543 include: [
545 { 544 {
546 model: VideoChannelModel.unscoped(), 545 model: VideoChannelModel.unscoped(),
@@ -592,10 +591,10 @@ export type AvailableForListIDsOptions = {
592 } 591 }
593 ] 592 ]
594 }, 593 },
595 [ ScopeNames.WITH_TAGS ]: { 594 [ScopeNames.WITH_TAGS]: {
596 include: [ TagModel ] 595 include: [ TagModel ]
597 }, 596 },
598 [ ScopeNames.WITH_BLACKLISTED ]: { 597 [ScopeNames.WITH_BLACKLISTED]: {
599 include: [ 598 include: [
600 { 599 {
601 attributes: [ 'id', 'reason', 'unfederated' ], 600 attributes: [ 'id', 'reason', 'unfederated' ],
@@ -604,7 +603,7 @@ export type AvailableForListIDsOptions = {
604 } 603 }
605 ] 604 ]
606 }, 605 },
607 [ ScopeNames.WITH_WEBTORRENT_FILES ]: (withRedundancies = false) => { 606 [ScopeNames.WITH_WEBTORRENT_FILES]: (withRedundancies = false) => {
608 let subInclude: any[] = [] 607 let subInclude: any[] = []
609 608
610 if (withRedundancies === true) { 609 if (withRedundancies === true) {
@@ -628,7 +627,7 @@ export type AvailableForListIDsOptions = {
628 ] 627 ]
629 } 628 }
630 }, 629 },
631 [ ScopeNames.WITH_STREAMING_PLAYLISTS ]: (withRedundancies = false) => { 630 [ScopeNames.WITH_STREAMING_PLAYLISTS]: (withRedundancies = false) => {
632 const subInclude: IncludeOptions[] = [ 631 const subInclude: IncludeOptions[] = [
633 { 632 {
634 model: VideoFileModel.unscoped(), 633 model: VideoFileModel.unscoped(),
@@ -655,7 +654,7 @@ export type AvailableForListIDsOptions = {
655 ] 654 ]
656 } 655 }
657 }, 656 },
658 [ ScopeNames.WITH_SCHEDULED_UPDATE ]: { 657 [ScopeNames.WITH_SCHEDULED_UPDATE]: {
659 include: [ 658 include: [
660 { 659 {
661 model: ScheduleVideoUpdateModel.unscoped(), 660 model: ScheduleVideoUpdateModel.unscoped(),
@@ -663,7 +662,7 @@ export type AvailableForListIDsOptions = {
663 } 662 }
664 ] 663 ]
665 }, 664 },
666 [ ScopeNames.WITH_USER_HISTORY ]: (userId: number) => { 665 [ScopeNames.WITH_USER_HISTORY]: (userId: number) => {
667 return { 666 return {
668 include: [ 667 include: [
669 { 668 {
@@ -1016,7 +1015,7 @@ export class VideoModel extends Model<VideoModel> {
1016 }, 1015 },
1017 onDelete: 'cascade', 1016 onDelete: 'cascade',
1018 hooks: true, 1017 hooks: true,
1019 [ 'separate' as any ]: true 1018 ['separate' as any]: true
1020 }) 1019 })
1021 VideoCaptions: VideoCaptionModel[] 1020 VideoCaptions: VideoCaptionModel[]
1022 1021
@@ -1112,9 +1111,9 @@ export class VideoModel extends Model<VideoModel> {
1112 order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings 1111 order: getVideoSort('createdAt', [ 'Tags', 'name', 'ASC' ] as any), // FIXME: sequelize typings
1113 where: { 1112 where: {
1114 id: { 1113 id: {
1115 [ Op.in ]: Sequelize.literal('(' + rawQuery + ')') 1114 [Op.in]: Sequelize.literal('(' + rawQuery + ')')
1116 }, 1115 },
1117 [ Op.or ]: [ 1116 [Op.or]: [
1118 { privacy: VideoPrivacy.PUBLIC }, 1117 { privacy: VideoPrivacy.PUBLIC },
1119 { privacy: VideoPrivacy.UNLISTED } 1118 { privacy: VideoPrivacy.UNLISTED }
1120 ] 1119 ]
@@ -1131,10 +1130,10 @@ export class VideoModel extends Model<VideoModel> {
1131 required: false, 1130 required: false,
1132 // We only want videos shared by this actor 1131 // We only want videos shared by this actor
1133 where: { 1132 where: {
1134 [ Op.and ]: [ 1133 [Op.and]: [
1135 { 1134 {
1136 id: { 1135 id: {
1137 [ Op.not ]: null 1136 [Op.not]: null
1138 } 1137 }
1139 }, 1138 },
1140 { 1139 {
@@ -1184,8 +1183,8 @@ export class VideoModel extends Model<VideoModel> {
1184 // totals: totalVideos + totalVideoShares 1183 // totals: totalVideos + totalVideoShares
1185 let totalVideos = 0 1184 let totalVideos = 0
1186 let totalVideoShares = 0 1185 let totalVideoShares = 0
1187 if (totals[ 0 ]) totalVideos = parseInt(totals[ 0 ].total, 10) 1186 if (totals[0]) totalVideos = parseInt(totals[0].total, 10)
1188 if (totals[ 1 ]) totalVideoShares = parseInt(totals[ 1 ].total, 10) 1187 if (totals[1]) totalVideoShares = parseInt(totals[1].total, 10)
1189 1188
1190 const total = totalVideos + totalVideoShares 1189 const total = totalVideos + totalVideoShares
1191 return { 1190 return {
@@ -1228,7 +1227,7 @@ export class VideoModel extends Model<VideoModel> {
1228 baseQuery = Object.assign(baseQuery, { 1227 baseQuery = Object.assign(baseQuery, {
1229 where: { 1228 where: {
1230 name: { 1229 name: {
1231 [ Op.iLike ]: '%' + search + '%' 1230 [Op.iLike]: '%' + search + '%'
1232 } 1231 }
1233 } 1232 }
1234 }) 1233 })
@@ -1258,25 +1257,25 @@ export class VideoModel extends Model<VideoModel> {
1258 } 1257 }
1259 1258
1260 static async listForApi (options: { 1259 static async listForApi (options: {
1261 start: number, 1260 start: number
1262 count: number, 1261 count: number
1263 sort: string, 1262 sort: string
1264 nsfw: boolean, 1263 nsfw: boolean
1265 includeLocalVideos: boolean, 1264 includeLocalVideos: boolean
1266 withFiles: boolean, 1265 withFiles: boolean
1267 categoryOneOf?: number[], 1266 categoryOneOf?: number[]
1268 licenceOneOf?: number[], 1267 licenceOneOf?: number[]
1269 languageOneOf?: string[], 1268 languageOneOf?: string[]
1270 tagsOneOf?: string[], 1269 tagsOneOf?: string[]
1271 tagsAllOf?: string[], 1270 tagsAllOf?: string[]
1272 filter?: VideoFilter, 1271 filter?: VideoFilter
1273 accountId?: number, 1272 accountId?: number
1274 videoChannelId?: number, 1273 videoChannelId?: number
1275 followerActorId?: number 1274 followerActorId?: number
1276 videoPlaylistId?: number, 1275 videoPlaylistId?: number
1277 trendingDays?: number, 1276 trendingDays?: number
1278 user?: MUserAccountId, 1277 user?: MUserAccountId
1279 historyOfUser?: MUserId, 1278 historyOfUser?: MUserId
1280 countVideos?: boolean 1279 countVideos?: boolean
1281 }) { 1280 }) {
1282 if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { 1281 if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
@@ -1342,7 +1341,7 @@ export class VideoModel extends Model<VideoModel> {
1342 tagsAllOf?: string[] 1341 tagsAllOf?: string[]
1343 durationMin?: number // seconds 1342 durationMin?: number // seconds
1344 durationMax?: number // seconds 1343 durationMax?: number // seconds
1345 user?: MUserAccountId, 1344 user?: MUserAccountId
1346 filter?: VideoFilter 1345 filter?: VideoFilter
1347 }) { 1346 }) {
1348 const whereAnd = [] 1347 const whereAnd = []
@@ -1350,8 +1349,8 @@ export class VideoModel extends Model<VideoModel> {
1350 if (options.startDate || options.endDate) { 1349 if (options.startDate || options.endDate) {
1351 const publishedAtRange = {} 1350 const publishedAtRange = {}
1352 1351
1353 if (options.startDate) publishedAtRange[ Op.gte ] = options.startDate 1352 if (options.startDate) publishedAtRange[Op.gte] = options.startDate
1354 if (options.endDate) publishedAtRange[ Op.lte ] = options.endDate 1353 if (options.endDate) publishedAtRange[Op.lte] = options.endDate
1355 1354
1356 whereAnd.push({ publishedAt: publishedAtRange }) 1355 whereAnd.push({ publishedAt: publishedAtRange })
1357 } 1356 }
@@ -1359,8 +1358,8 @@ export class VideoModel extends Model<VideoModel> {
1359 if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) { 1358 if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
1360 const originallyPublishedAtRange = {} 1359 const originallyPublishedAtRange = {}
1361 1360
1362 if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Op.gte ] = options.originallyPublishedStartDate 1361 if (options.originallyPublishedStartDate) originallyPublishedAtRange[Op.gte] = options.originallyPublishedStartDate
1363 if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Op.lte ] = options.originallyPublishedEndDate 1362 if (options.originallyPublishedEndDate) originallyPublishedAtRange[Op.lte] = options.originallyPublishedEndDate
1364 1363
1365 whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange }) 1364 whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
1366 } 1365 }
@@ -1368,8 +1367,8 @@ export class VideoModel extends Model<VideoModel> {
1368 if (options.durationMin || options.durationMax) { 1367 if (options.durationMin || options.durationMax) {
1369 const durationRange = {} 1368 const durationRange = {}
1370 1369
1371 if (options.durationMin) durationRange[ Op.gte ] = options.durationMin 1370 if (options.durationMin) durationRange[Op.gte] = options.durationMin
1372 if (options.durationMax) durationRange[ Op.lte ] = options.durationMax 1371 if (options.durationMax) durationRange[Op.lte] = options.durationMax
1373 1372
1374 whereAnd.push({ duration: durationRange }) 1373 whereAnd.push({ duration: durationRange })
1375 } 1374 }
@@ -1380,7 +1379,7 @@ export class VideoModel extends Model<VideoModel> {
1380 if (options.search) { 1379 if (options.search) {
1381 const trigramSearch = { 1380 const trigramSearch = {
1382 id: { 1381 id: {
1383 [ Op.in ]: Sequelize.literal( 1382 [Op.in]: Sequelize.literal(
1384 '(' + 1383 '(' +
1385 'SELECT "video"."id" FROM "video" ' + 1384 'SELECT "video"."id" FROM "video" ' +
1386 'WHERE ' + 1385 'WHERE ' +
@@ -1578,8 +1577,8 @@ export class VideoModel extends Model<VideoModel> {
1578 } 1577 }
1579 1578
1580 static loadForGetAPI (parameters: { 1579 static loadForGetAPI (parameters: {
1581 id: number | string, 1580 id: number | string
1582 t?: Transaction, 1581 t?: Transaction
1583 userId?: number 1582 userId?: number
1584 }): Bluebird<MVideoDetails> { 1583 }): Bluebird<MVideoDetails> {
1585 const { id, t, userId } = parameters 1584 const { id, t, userId } = parameters
@@ -1645,9 +1644,9 @@ export class VideoModel extends Model<VideoModel> {
1645 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) { 1644 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) {
1646 // Instances only share videos 1645 // Instances only share videos
1647 const query = 'SELECT 1 FROM "videoShare" ' + 1646 const query = 'SELECT 1 FROM "videoShare" ' +
1648 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + 1647 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
1649 'WHERE "actorFollow"."actorId" = $followerActorId AND "videoShare"."videoId" = $videoId ' + 1648 'WHERE "actorFollow"."actorId" = $followerActorId AND "videoShare"."videoId" = $videoId ' +
1650 'LIMIT 1' 1649 'LIMIT 1'
1651 1650
1652 const options = { 1651 const options = {
1653 type: QueryTypes.SELECT as QueryTypes.SELECT, 1652 type: QueryTypes.SELECT as QueryTypes.SELECT,
@@ -1679,7 +1678,7 @@ export class VideoModel extends Model<VideoModel> {
1679 } 1678 }
1680 1679
1681 return VideoModel.findAll(query) 1680 return VideoModel.findAll(query)
1682 .then(videos => videos.map(v => v.id)) 1681 .then(videos => videos.map(v => v.id))
1683 } 1682 }
1684 1683
1685 // threshold corresponds to how many video the field should have to be returned 1684 // threshold corresponds to how many video the field should have to be returned
@@ -1699,14 +1698,14 @@ export class VideoModel extends Model<VideoModel> {
1699 limit: count, 1698 limit: count,
1700 group: field, 1699 group: field,
1701 having: Sequelize.where( 1700 having: Sequelize.where(
1702 Sequelize.fn('COUNT', Sequelize.col(field)), { [ Op.gte ]: threshold } 1701 Sequelize.fn('COUNT', Sequelize.col(field)), { [Op.gte]: threshold }
1703 ), 1702 ),
1704 order: [ (this.sequelize as any).random() ] 1703 order: [ (this.sequelize as any).random() ]
1705 } 1704 }
1706 1705
1707 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST_IDS, scopeOptions ] }) 1706 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST_IDS, scopeOptions ] })
1708 .findAll(query) 1707 .findAll(query)
1709 .then(rows => rows.map(r => r[ field ])) 1708 .then(rows => rows.map(r => r[field]))
1710 } 1709 }
1711 1710
1712 static buildTrendingQuery (trendingDays: number) { 1711 static buildTrendingQuery (trendingDays: number) {
@@ -1717,7 +1716,7 @@ export class VideoModel extends Model<VideoModel> {
1717 required: false, 1716 required: false,
1718 where: { 1717 where: {
1719 startDate: { 1718 startDate: {
1720 [ Op.gte ]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays) 1719 [Op.gte]: new Date(new Date().getTime() - (24 * 3600 * 1000) * trendingDays)
1721 } 1720 }
1722 } 1721 }
1723 } 1722 }
@@ -1800,23 +1799,23 @@ export class VideoModel extends Model<VideoModel> {
1800 } 1799 }
1801 1800
1802 static getCategoryLabel (id: number) { 1801 static getCategoryLabel (id: number) {
1803 return VIDEO_CATEGORIES[ id ] || 'Misc' 1802 return VIDEO_CATEGORIES[id] || 'Misc'
1804 } 1803 }
1805 1804
1806 static getLicenceLabel (id: number) { 1805 static getLicenceLabel (id: number) {
1807 return VIDEO_LICENCES[ id ] || 'Unknown' 1806 return VIDEO_LICENCES[id] || 'Unknown'
1808 } 1807 }
1809 1808
1810 static getLanguageLabel (id: string) { 1809 static getLanguageLabel (id: string) {
1811 return VIDEO_LANGUAGES[ id ] || 'Unknown' 1810 return VIDEO_LANGUAGES[id] || 'Unknown'
1812 } 1811 }
1813 1812
1814 static getPrivacyLabel (id: number) { 1813 static getPrivacyLabel (id: number) {
1815 return VIDEO_PRIVACIES[ id ] || 'Unknown' 1814 return VIDEO_PRIVACIES[id] || 'Unknown'
1816 } 1815 }
1817 1816
1818 static getStateLabel (id: number) { 1817 static getStateLabel (id: number) {
1819 return VIDEO_STATES[ id ] || 'Unknown' 1818 return VIDEO_STATES[id] || 'Unknown'
1820 } 1819 }
1821 1820
1822 isBlacklisted () { 1821 isBlacklisted () {
@@ -1828,7 +1827,7 @@ export class VideoModel extends Model<VideoModel> {
1828 this.VideoChannel.Account.isBlocked() 1827 this.VideoChannel.Account.isBlocked()
1829 } 1828 }
1830 1829
1831 getQualityFileBy <T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) { 1830 getQualityFileBy<T extends MVideoWithFile> (this: T, fun: (files: MVideoFile[], it: (file: MVideoFile) => number) => MVideoFile) {
1832 if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) { 1831 if (Array.isArray(this.VideoFiles) && this.VideoFiles.length !== 0) {
1833 const file = fun(this.VideoFiles, file => file.resolution) 1832 const file = fun(this.VideoFiles, file => file.resolution)
1834 1833
@@ -1846,15 +1845,15 @@ export class VideoModel extends Model<VideoModel> {
1846 return undefined 1845 return undefined
1847 } 1846 }
1848 1847
1849 getMaxQualityFile <T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { 1848 getMaxQualityFile<T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo {
1850 return this.getQualityFileBy(maxBy) 1849 return this.getQualityFileBy(maxBy)
1851 } 1850 }
1852 1851
1853 getMinQualityFile <T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo { 1852 getMinQualityFile<T extends MVideoWithFile> (this: T): MVideoFileVideo | MVideoFileStreamingPlaylistVideo {
1854 return this.getQualityFileBy(minBy) 1853 return this.getQualityFileBy(minBy)
1855 } 1854 }
1856 1855
1857 getWebTorrentFile <T extends MVideoWithFile> (this: T, resolution: number): MVideoFileVideo { 1856 getWebTorrentFile<T extends MVideoWithFile> (this: T, resolution: number): MVideoFileVideo {
1858 if (Array.isArray(this.VideoFiles) === false) return undefined 1857 if (Array.isArray(this.VideoFiles) === false) return undefined
1859 1858
1860 const file = this.VideoFiles.find(f => f.resolution === resolution) 1859 const file = this.VideoFiles.find(f => f.resolution === resolution)
@@ -1977,8 +1976,8 @@ export class VideoModel extends Model<VideoModel> {
1977 } 1976 }
1978 1977
1979 this.VideoStreamingPlaylists = this.VideoStreamingPlaylists 1978 this.VideoStreamingPlaylists = this.VideoStreamingPlaylists
1980 .filter(s => s.type !== VideoStreamingPlaylistType.HLS) 1979 .filter(s => s.type !== VideoStreamingPlaylistType.HLS)
1981 .concat(toAdd) 1980 .concat(toAdd)
1982 } 1981 }
1983 1982
1984 removeFile (videoFile: MVideoFile, isRedundancy = false) { 1983 removeFile (videoFile: MVideoFile, isRedundancy = false) {
@@ -1999,7 +1998,7 @@ export class VideoModel extends Model<VideoModel> {
1999 await remove(directoryPath) 1998 await remove(directoryPath)
2000 1999
2001 if (isRedundancy !== true) { 2000 if (isRedundancy !== true) {
2002 let streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo 2001 const streamingPlaylistWithFiles = streamingPlaylist as MStreamingPlaylistFilesVideo
2003 streamingPlaylistWithFiles.Video = this 2002 streamingPlaylistWithFiles.Video = this
2004 2003
2005 if (!Array.isArray(streamingPlaylistWithFiles.VideoFiles)) { 2004 if (!Array.isArray(streamingPlaylistWithFiles.VideoFiles)) {