1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Add quota used in users list

This commit is contained in:
Chocobozzz 2018-08-14 17:56:51 +02:00
parent 614d1ae928
commit a76138ff56
No known key found for this signature in database
GPG key ID: 583A612D890159BE
6 changed files with 44 additions and 10 deletions

View file

@ -161,6 +161,25 @@ export class UserModel extends Model<UserModel> {
static listForApi (start: number, count: number, sort: string) {
const query = {
attributes: {
include: [
[
Sequelize.literal(
'(' +
'SELECT COALESCE(SUM("size"), 0) FROM ' +
'(' +
'SELECT MAX("videoFile"."size") AS "size" FROM "videoFile" ' +
'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
'WHERE "account"."userId" = "UserModel"."id" GROUP BY "video"."id"' +
') t' +
')'
),
'videoQuotaUsed'
] as any // FIXME: typings
]
},
offset: start,
limit: count,
order: getSort(sort)
@ -168,6 +187,9 @@ export class UserModel extends Model<UserModel> {
return UserModel.findAndCountAll(query)
.then(({ rows, count }) => {
console.log(rows[0])
console.log(rows[0]['videoQuotaUsed'])
console.log(rows[0].get('videoQuotaUsed'))
return {
data: rows,
total: count
@ -249,8 +271,7 @@ export class UserModel extends Model<UserModel> {
'INNER JOIN "video" ON "videoFile"."videoId" = "video"."id" ' +
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
'INNER JOIN "account" ON "videoChannel"."accountId" = "account"."id" ' +
'INNER JOIN "user" ON "account"."userId" = "user"."id" ' +
'WHERE "user"."id" = $userId GROUP BY "video"."id") t'
'WHERE "account"."userId" = $userId GROUP BY "video"."id") t'
const options = {
bind: { userId: user.id },
@ -281,6 +302,8 @@ export class UserModel extends Model<UserModel> {
}
toFormattedJSON (): User {
const videoQuotaUsed = this.get('videoQuotaUsed')
const json = {
id: this.id,
username: this.username,
@ -294,7 +317,8 @@ export class UserModel extends Model<UserModel> {
blocked: this.blocked,
blockedReason: this.blockedReason,
account: this.Account.toFormattedJSON(),
videoChannels: []
videoChannels: [],
videoQuotaUsed: videoQuotaUsed !== undefined ? parseInt(videoQuotaUsed, 10) : undefined
}
if (Array.isArray(this.Account.VideoChannels) === true) {