diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-23 09:50:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:21 +0200 |
commit | 3acc50844047a37698f0618fa235c138e386a053 (patch) | |
tree | e33243bf7fadbcf2df616fc41814245094fd881a /server/models/video/video-file.ts | |
parent | 1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff) | |
download | PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip |
Upgrade sequelize
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r-- | server/models/video/video-file.ts | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index c14d96bc5..2203a7aba 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -19,11 +19,11 @@ import { | |||
19 | isVideoFileSizeValid, | 19 | isVideoFileSizeValid, |
20 | isVideoFPSResolutionValid | 20 | isVideoFPSResolutionValid |
21 | } from '../../helpers/custom-validators/videos' | 21 | } from '../../helpers/custom-validators/videos' |
22 | import { throwIfNotValid } from '../utils' | 22 | import { parseAggregateResult, throwIfNotValid } from '../utils' |
23 | import { VideoModel } from './video' | 23 | import { VideoModel } from './video' |
24 | import * as Sequelize from 'sequelize' | ||
25 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 24 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
26 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 25 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
26 | import { FindOptions, QueryTypes, Transaction } from 'sequelize' | ||
27 | 27 | ||
28 | @Table({ | 28 | @Table({ |
29 | tableName: 'videoFile', | 29 | tableName: 'videoFile', |
@@ -97,15 +97,13 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
97 | static doesInfohashExist (infoHash: string) { | 97 | static doesInfohashExist (infoHash: string) { |
98 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' | 98 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' |
99 | const options = { | 99 | const options = { |
100 | type: Sequelize.QueryTypes.SELECT, | 100 | type: QueryTypes.SELECT, |
101 | bind: { infoHash }, | 101 | bind: { infoHash }, |
102 | raw: true | 102 | raw: true |
103 | } | 103 | } |
104 | 104 | ||
105 | return VideoModel.sequelize.query(query, options) | 105 | return VideoModel.sequelize.query(query, options) |
106 | .then(results => { | 106 | .then(results => results.length === 1) |
107 | return results.length === 1 | ||
108 | }) | ||
109 | } | 107 | } |
110 | 108 | ||
111 | static loadWithVideo (id: number) { | 109 | static loadWithVideo (id: number) { |
@@ -121,7 +119,7 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
121 | return VideoFileModel.findByPk(id, options) | 119 | return VideoFileModel.findByPk(id, options) |
122 | } | 120 | } |
123 | 121 | ||
124 | static listByStreamingPlaylist (streamingPlaylistId: number, transaction: Sequelize.Transaction) { | 122 | static listByStreamingPlaylist (streamingPlaylistId: number, transaction: Transaction) { |
125 | const query = { | 123 | const query = { |
126 | include: [ | 124 | include: [ |
127 | { | 125 | { |
@@ -144,8 +142,8 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
144 | return VideoFileModel.findAll(query) | 142 | return VideoFileModel.findAll(query) |
145 | } | 143 | } |
146 | 144 | ||
147 | static async getStats () { | 145 | static getStats () { |
148 | let totalLocalVideoFilesSize = await VideoFileModel.sum('size', { | 146 | const query: FindOptions = { |
149 | include: [ | 147 | include: [ |
150 | { | 148 | { |
151 | attributes: [], | 149 | attributes: [], |
@@ -155,13 +153,12 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
155 | } | 153 | } |
156 | } | 154 | } |
157 | ] | 155 | ] |
158 | } as any) | ||
159 | // Sequelize could return null... | ||
160 | if (!totalLocalVideoFilesSize) totalLocalVideoFilesSize = 0 | ||
161 | |||
162 | return { | ||
163 | totalLocalVideoFilesSize | ||
164 | } | 156 | } |
157 | |||
158 | return VideoFileModel.aggregate('size', 'SUM', query) | ||
159 | .then(result => ({ | ||
160 | totalLocalVideoFilesSize: parseAggregateResult(result) | ||
161 | })) | ||
165 | } | 162 | } |
166 | 163 | ||
167 | hasSameUniqueKeysThan (other: VideoFileModel) { | 164 | hasSameUniqueKeysThan (other: VideoFileModel) { |