aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-14 17:56:51 +0200
committerChocobozzz <me@florianbigard.com>2018-08-14 18:01:23 +0200
commita76138ff56ad3ad2df926f59578a06b22fb1f93c (patch)
tree2b97808cbb492af2356beb26d02749223abc6154 /server/models/account
parent614d1ae928ec307b708c4a3eb423797353b1df2a (diff)
downloadPeerTube-a76138ff56ad3ad2df926f59578a06b22fb1f93c.tar.gz
PeerTube-a76138ff56ad3ad2df926f59578a06b22fb1f93c.tar.zst
PeerTube-a76138ff56ad3ad2df926f59578a06b22fb1f93c.zip
Add quota used in users list
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/user.ts30
1 files changed, 27 insertions, 3 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 81b0651fd..0150df4ce 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -161,6 +161,25 @@ export class UserModel extends Model<UserModel> {
161 161
162 static listForApi (start: number, count: number, sort: string) { 162 static listForApi (start: number, count: number, sort: string) {
163 const query = { 163 const query = {
164 attributes: {
165 include: [
166 [
167 Sequelize.literal(
168 '(' +
169 'SELECT COALESCE(SUM("size"), 0) FROM ' +
170 '(' +
171 'SELECT MAX("videoFile"."size") AS "size" FROM "videoFile" ' +
172 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
173 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
174 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
175 'WHERE "account"."userId" = "UserModel"."id" GROUP BY "video"."id"' +
176 ') t' +
177 ')'
178 ),
179 'videoQuotaUsed'
180 ] as any // FIXME: typings
181 ]
182 },
164 offset: start, 183 offset: start,
165 limit: count, 184 limit: count,
166 order: getSort(sort) 185 order: getSort(sort)
@@ -168,6 +187,9 @@ export class UserModel extends Model<UserModel> {
168 187
169 return UserModel.findAndCountAll(query) 188 return UserModel.findAndCountAll(query)
170 .then(({ rows, count }) => { 189 .then(({ rows, count }) => {
190 console.log(rows[0])
191 console.log(rows[0]['videoQuotaUsed'])
192 console.log(rows[0].get('videoQuotaUsed'))
171 return { 193 return {
172 data: rows, 194 data: rows,
173 total: count 195 total: count
@@ -249,8 +271,7 @@ export class UserModel extends Model<UserModel> {
249 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' + 271 'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
250 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + 272 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
251 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' + 273 'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
252 'INNER JOIN "user" ON "account"."userId" = "user"."id" ' + 274 'WHERE "account"."userId" = $userId GROUP BY "video"."id") t'
253 'WHERE "user"."id" = $userId GROUP BY "video"."id") t'
254 275
255 const options = { 276 const options = {
256 bind: { userId: user.id }, 277 bind: { userId: user.id },
@@ -281,6 +302,8 @@ export class UserModel extends Model<UserModel> {
281 } 302 }
282 303
283 toFormattedJSON (): User { 304 toFormattedJSON (): User {
305 const videoQuotaUsed = this.get('videoQuotaUsed')
306
284 const json = { 307 const json = {
285 id: this.id, 308 id: this.id,
286 username: this.username, 309 username: this.username,
@@ -294,7 +317,8 @@ export class UserModel extends Model<UserModel> {
294 blocked: this.blocked, 317 blocked: this.blocked,
295 blockedReason: this.blockedReason, 318 blockedReason: this.blockedReason,
296 account: this.Account.toFormattedJSON(), 319 account: this.Account.toFormattedJSON(),
297 videoChannels: [] 320 videoChannels: [],
321 videoQuotaUsed: videoQuotaUsed !== undefined ? parseInt(videoQuotaUsed, 10) : undefined
298 } 322 }
299 323
300 if (Array.isArray(this.Account.VideoChannels) === true) { 324 if (Array.isArray(this.Account.VideoChannels) === true) {