diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-08 14:30:29 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-12-09 11:41:22 +0100 |
commit | b49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch) | |
tree | a2825877d7b3b53454804a79c9d2a14c5d37385c /server/models/redundancy/video-redundancy.ts | |
parent | 6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff) | |
download | PeerTube-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.ts | 45 |
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 @@ | |||
1 | import { sample } from 'lodash' | ||
2 | import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize' | ||
1 | import { | 3 | import { |
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' |
15 | import { ActorModel } from '../activitypub/actor' | 17 | import { getServerActor } from '@server/models/application/application' |
16 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' | ||
17 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
18 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' | ||
19 | import { VideoFileModel } from '../video/video-file' | ||
20 | import { VideoModel } from '../video/video' | ||
21 | import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy' | ||
22 | import { logger } from '../../helpers/logger' | ||
23 | import { CacheFileObject, VideoPrivacy } from '../../../shared' | ||
24 | import { VideoChannelModel } from '../video/video-channel' | ||
25 | import { ServerModel } from '../server/server' | ||
26 | import { sample } from 'lodash' | ||
27 | import { isTestInstance } from '../../helpers/core-utils' | ||
28 | import * as Bluebird from 'bluebird' | ||
29 | import { col, FindOptions, fn, literal, Op, Transaction, WhereOptions } from 'sequelize' | ||
30 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' | ||
31 | import { CONFIG } from '../../initializers/config' | ||
32 | import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' | 18 | import { MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' |
33 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' | 19 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' |
34 | import { | 20 | import { |
@@ -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' |
39 | import { getServerActor } from '@server/models/application/application' | 25 | import { CacheFileObject, VideoPrivacy } from '../../../shared' |
26 | import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy' | ||
27 | import { isTestInstance } from '../../helpers/core-utils' | ||
28 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
29 | import { logger } from '../../helpers/logger' | ||
30 | import { CONFIG } from '../../initializers/config' | ||
31 | import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' | ||
32 | import { ActorModel } from '../activitypub/actor' | ||
33 | import { ServerModel } from '../server/server' | ||
34 | import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' | ||
35 | import { VideoModel } from '../video/video' | ||
36 | import { VideoChannelModel } from '../video/video-channel' | ||
37 | import { VideoFileModel } from '../video/video-file' | ||
38 | import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' | ||
40 | 39 | ||
41 | export enum ScopeNames { | 40 | export 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 | }) |
87 | export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | 86 | export 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 | ||