aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2018-08-28 02:01:35 -0500
committerChocobozzz <me@florianbigard.com>2018-08-28 09:01:35 +0200
commitbee0abffff73804d816b90c7fd599e0a51c09d61 (patch)
treefae6d58637f9c63a3800090277f8e130b43442dd /server/controllers/api/users
parentc907c2fa3fd7c0a741117a0204d0ebca675124bd (diff)
downloadPeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.tar.gz
PeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.tar.zst
PeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.zip
Implement daily upload limit (#956)
* Implement daily upload limit (ref #652) * remove duplicate code * review fixes * fix tests? * whitespace fixes, finish leftover todo * fix tests * added some new tests * use different config value for tests * remove todo
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r--server/controllers/api/users/index.ts7
-rw-r--r--server/controllers/api/users/me.ts4
2 files changed, 8 insertions, 3 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 608d439ac..25d51ae5e 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -134,7 +134,8 @@ async function createUser (req: express.Request, res: express.Response) {
134 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 134 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
135 autoPlayVideo: true, 135 autoPlayVideo: true,
136 role: body.role, 136 role: body.role,
137 videoQuota: body.videoQuota 137 videoQuota: body.videoQuota,
138 videoQuotaDaily: body.videoQuotaDaily
138 }) 139 })
139 140
140 const { user, account } = await createUserAccountAndChannel(userToCreate) 141 const { user, account } = await createUserAccountAndChannel(userToCreate)
@@ -163,7 +164,8 @@ async function registerUser (req: express.Request, res: express.Response) {
163 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, 164 nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
164 autoPlayVideo: true, 165 autoPlayVideo: true,
165 role: UserRole.USER, 166 role: UserRole.USER,
166 videoQuota: CONFIG.USER.VIDEO_QUOTA 167 videoQuota: CONFIG.USER.VIDEO_QUOTA,
168 videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
167 }) 169 })
168 170
169 const { user } = await createUserAccountAndChannel(userToCreate) 171 const { user } = await createUserAccountAndChannel(userToCreate)
@@ -219,6 +221,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
219 221
220 if (body.email !== undefined) userToUpdate.email = body.email 222 if (body.email !== undefined) userToUpdate.email = body.email
221 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota 223 if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota
224 if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
222 if (body.role !== undefined) userToUpdate.role = body.role 225 if (body.role !== undefined) userToUpdate.role = body.role
223 226
224 const user = await userToUpdate.save() 227 const user = await userToUpdate.save()
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 000c706b5..0f18b42f9 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -283,9 +283,11 @@ async function getUserVideoQuotaUsed (req: express.Request, res: express.Respons
283 // We did not load channels in res.locals.user 283 // We did not load channels in res.locals.user
284 const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) 284 const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
285 const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user) 285 const videoQuotaUsed = await UserModel.getOriginalVideoFileTotalFromUser(user)
286 const videoQuotaUsedDaily = await UserModel.getOriginalVideoFileTotalDailyFromUser(user)
286 287
287 const data: UserVideoQuota = { 288 const data: UserVideoQuota = {
288 videoQuotaUsed 289 videoQuotaUsed,
290 videoQuotaUsedDaily
289 } 291 }
290 return res.json(data) 292 return res.json(data)
291} 293}