aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/redundancy/video-redundancy.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-08 14:30:29 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-09 11:41:22 +0100
commitb49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch)
treea2825877d7b3b53454804a79c9d2a14c5d37385c /server/models/redundancy/video-redundancy.ts
parent6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff)
downloadPeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.gz
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.zst
PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.zip
Upgrade sequelize to v6
Diffstat (limited to 'server/models/redundancy/video-redundancy.ts')
-rw-r--r--server/models/redundancy/video-redundancy.ts45
1 files changed, 22 insertions, 23 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index 1b967996c..fa96a1e39 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -1,3 +1,5 @@
1import { sample } from 'lodash'
2import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize'
1import { 3import {
2 AllowNull, 4 AllowNull,
3 BeforeDestroy, 5 BeforeDestroy,
@@ -12,23 +14,7 @@ import {
12 Table, 14 Table,
13 UpdatedAt 15 UpdatedAt
14} from 'sequelize-typescript' 16} from 'sequelize-typescript'
15import { ActorModel } from '../activitypub/actor' 17import { getServerActor } from '@server/models/application/application'
16import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils'
17import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
18import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants'
19import { VideoFileModel } from '../video/video-file'
20import { VideoModel } from '../video/video'
21import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy'
22import { logger } from '../../helpers/logger'
23import { CacheFileObject, VideoPrivacy } from '../../../shared'
24import { VideoChannelModel } from '../video/video-channel'
25import { ServerModel } from '../server/server'
26import { sample } from 'lodash'
27import { isTestInstance } from '../../helpers/core-utils'
28import * as Bluebird from 'bluebird'
29import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize'
30import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist'
31import { CONFIG } from '../../initializers/config'
32import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' 18import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models'
33import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' 19import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model'
34import { 20import {
@@ -36,7 +22,20 @@ import {
36 StreamingPlaylistRedundancyInformation, 22 StreamingPlaylistRedundancyInformation,
37 VideoRedundancy 23 VideoRedundancy
38} from '@shared/models/redundancy/video-redundancy.model' 24} from '@shared/models/redundancy/video-redundancy.model'
39import { getServerActor } from '@server/models/application/application' 25import { CacheFileObject, VideoPrivacy } from '../../../shared'
26import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy'
27import { isTestInstance } from '../../helpers/core-utils'
28import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
29import { logger } from '../../helpers/logger'
30import { CONFIG } from '../../initializers/config'
31import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants'
32import { ActorModel } from '../activitypub/actor'
33import { ServerModel } from '../server/server'
34import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils'
35import { VideoModel } from '../video/video'
36import { VideoChannelModel } from '../video/video-channel'
37import { VideoFileModel } from '../video/video-file'
38import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist'
40 39
41export enum ScopeNames { 40export enum ScopeNames {
42 WITH_VIDEO = 'WITH_VIDEO' 41 WITH_VIDEO = 'WITH_VIDEO'
@@ -84,7 +83,7 @@ export enum ScopeNames {
84 } 83 }
85 ] 84 ]
86}) 85})
87export class VideoRedundancyModel extends Model<VideoRedundancyModel> { 86export class VideoRedundancyModel extends Model {
88 87
89 @CreatedAt 88 @CreatedAt
90 createdAt: Date 89 createdAt: Date
@@ -199,7 +198,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
199 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) 198 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query)
200 } 199 }
201 200
202 static loadByIdWithVideo (id: number, transaction?: Transaction): Bluebird<MVideoRedundancyVideo> { 201 static loadByIdWithVideo (id: number, transaction?: Transaction): Promise<MVideoRedundancyVideo> {
203 const query = { 202 const query = {
204 where: { id }, 203 where: { id },
205 transaction 204 transaction
@@ -208,7 +207,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
208 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query) 207 return VideoRedundancyModel.scope(ScopeNames.WITH_VIDEO).findOne(query)
209 } 208 }
210 209
211 static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoRedundancy> { 210 static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoRedundancy> {
212 const query = { 211 const query = {
213 where: { 212 where: {
214 url 213 url
@@ -251,7 +250,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
251 .then(r => !!r) 250 .then(r => !!r)
252 } 251 }
253 252
254 static async getVideoSample (p: Bluebird<VideoModel[]>) { 253 static async getVideoSample (p: Promise<VideoModel[]>) {
255 const rows = await p 254 const rows = await p
256 if (rows.length === 0) return undefined 255 if (rows.length === 0) return undefined
257 256
@@ -696,7 +695,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> {
696 695
697 const notIn = literal( 696 const notIn = literal(
698 '(' + 697 '(' +
699 `SELECT "videoFileId" FROM "videoRedundancy" WHERE "actorId" = ${actor.id} AND "videoFileId" IS NOT NULL` + 698 `SELECT "videoFileId" FROM "videoRedundancy" WHERE "actorId" = ${actor.id} AND "videoFileId" IS NOT NULL` +
700 ')' 699 ')'
701 ) 700 )
702 701