aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/user/user.ts')
-rw-r--r--server/models/user/user.ts26
1 files changed, 12 insertions, 14 deletions
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 9bf13ad24..79a595528 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -242,25 +242,26 @@ loadByUsernameOrEmail = function (username: string, email: string) {
242// --------------------------------------------------------------------------- 242// ---------------------------------------------------------------------------
243 243
244function getOriginalVideoFileTotalFromUser (user: UserInstance) { 244function getOriginalVideoFileTotalFromUser (user: UserInstance) {
245 // attributes = [] because we don't want other fields than the sum
245 const query = { 246 const query = {
246 attributes: [
247 Sequelize.fn('COUNT', Sequelize.col('User.Author.Video.VideoFile.size'), 'totalVideoBytes')
248 ],
249 where: { 247 where: {
250 id: user.id 248 resolution: 0 // Original, TODO: improve readability
251 }, 249 },
252 include: [ 250 include: [
253 { 251 {
254 model: User['sequelize'].models.Author, 252 attributes: [],
255 required: true, 253 model: User['sequelize'].models.Video,
256 include: [ 254 include: [
257 { 255 {
258 model: User['sequelize'].models.Video, 256 attributes: [],
259 required: true, 257 model: User['sequelize'].models.Author,
260 include: [ 258 include: [
261 { 259 {
262 model: User['sequelize'].models.VideoFile, 260 attributes: [],
263 required: true 261 model: User['sequelize'].models.User,
262 where: {
263 id: user.id
264 }
264 } 265 }
265 ] 266 ]
266 } 267 }
@@ -269,8 +270,5 @@ function getOriginalVideoFileTotalFromUser (user: UserInstance) {
269 ] 270 ]
270 } 271 }
271 272
272 // FIXME: cast to any because of bad typing... 273 return User['sequelize'].models.VideoFile.sum('size', query)
273 return User.findAll(query).then((res: any) => {
274 return res.totalVideoBytes
275 })
276} 274}