aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-06 16:35:40 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-06 17:28:20 +0200
commit77a5501f6413aff2f2a626b929dfda486fa9a3e6 (patch)
tree9f286d1b5a3bede13ea746530c8210c49a064b39 /server/models/user
parent5c98d3bf078852043cbdd582c01e3dc4f4b5b79f (diff)
downloadPeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.tar.gz
PeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.tar.zst
PeerTube-77a5501f6413aff2f2a626b929dfda486fa9a3e6.zip
Fix tests and user quota
Diffstat (limited to 'server/models/user')
-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}