aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-file.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r--server/models/video/video-file.ts27
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'
22import { throwIfNotValid } from '../utils' 22import { parseAggregateResult, throwIfNotValid } from '../utils'
23import { VideoModel } from './video' 23import { VideoModel } from './video'
24import * as Sequelize from 'sequelize'
25import { VideoRedundancyModel } from '../redundancy/video-redundancy' 24import { VideoRedundancyModel } from '../redundancy/video-redundancy'
26import { VideoStreamingPlaylistModel } from './video-streaming-playlist' 25import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
26import { 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) {