diff options
author | Felix Ableitner <me@nutomic.com> | 2018-08-28 02:01:35 -0500 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-28 09:01:35 +0200 |
commit | bee0abffff73804d816b90c7fd599e0a51c09d61 (patch) | |
tree | fae6d58637f9c63a3800090277f8e130b43442dd /server/initializers | |
parent | c907c2fa3fd7c0a741117a0204d0ebca675124bd (diff) | |
download | PeerTube-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/initializers')
-rw-r--r-- | server/initializers/checker.ts | 2 | ||||
-rw-r--r-- | server/initializers/constants.ts | 4 | ||||
-rw-r--r-- | server/initializers/installer.ts | 3 | ||||
-rw-r--r-- | server/initializers/migrations/0260-upload_quota_daily.ts | 23 |
4 files changed, 29 insertions, 3 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index 608123607..916e9067e 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -47,7 +47,7 @@ function checkMissedConfig () { | |||
47 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', | 47 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', |
48 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | 48 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', |
49 | 'log.level', | 49 | 'log.level', |
50 | 'user.video_quota', | 50 | 'user.video_quota', 'user.video_quota_daily', |
51 | 'cache.previews.size', 'admin.email', | 51 | 'cache.previews.size', 'admin.email', |
52 | 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | 52 | 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', |
53 | 'transcoding.enabled', 'transcoding.threads', | 53 | 'transcoding.enabled', 'transcoding.threads', |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index a0dd78f42..4111d04ec 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -202,7 +202,8 @@ const CONFIG = { | |||
202 | } | 202 | } |
203 | }, | 203 | }, |
204 | USER: { | 204 | USER: { |
205 | get VIDEO_QUOTA () { return config.get<number>('user.video_quota') } | 205 | get VIDEO_QUOTA () { return config.get<number>('user.video_quota') }, |
206 | get VIDEO_QUOTA_DAILY () { return config.get<number>('user.video_quota_daily') } | ||
206 | }, | 207 | }, |
207 | TRANSCODING: { | 208 | TRANSCODING: { |
208 | get ENABLED () { return config.get<boolean>('transcoding.enabled') }, | 209 | get ENABLED () { return config.get<boolean>('transcoding.enabled') }, |
@@ -263,6 +264,7 @@ const CONSTRAINTS_FIELDS = { | |||
263 | USERNAME: { min: 3, max: 20 }, // Length | 264 | USERNAME: { min: 3, max: 20 }, // Length |
264 | PASSWORD: { min: 6, max: 255 }, // Length | 265 | PASSWORD: { min: 6, max: 255 }, // Length |
265 | VIDEO_QUOTA: { min: -1 }, | 266 | VIDEO_QUOTA: { min: -1 }, |
267 | VIDEO_QUOTA_DAILY: { min: -1 }, | ||
266 | BLOCKED_REASON: { min: 3, max: 250 } // Length | 268 | BLOCKED_REASON: { min: 3, max: 250 } // Length |
267 | }, | 269 | }, |
268 | VIDEO_ABUSES: { | 270 | VIDEO_ABUSES: { |
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index e319164e4..d4aaec8fe 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -123,7 +123,8 @@ async function createOAuthAdminIfNotExist () { | |||
123 | password, | 123 | password, |
124 | role, | 124 | role, |
125 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, | 125 | nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, |
126 | videoQuota: -1 | 126 | videoQuota: -1, |
127 | videoQuotaDaily: -1 | ||
127 | } | 128 | } |
128 | const user = new UserModel(userData) | 129 | const user = new UserModel(userData) |
129 | 130 | ||
diff --git a/server/initializers/migrations/0260-upload_quota_daily.ts b/server/initializers/migrations/0260-upload_quota_daily.ts new file mode 100644 index 000000000..d25154ba6 --- /dev/null +++ b/server/initializers/migrations/0260-upload_quota_daily.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { CONSTRAINTS_FIELDS } from '../constants' | ||
3 | |||
4 | async function up (utils: { | ||
5 | transaction: Sequelize.Transaction | ||
6 | queryInterface: Sequelize.QueryInterface | ||
7 | sequelize: Sequelize.Sequelize | ||
8 | }): Promise<any> { | ||
9 | { | ||
10 | const data = { | ||
11 | type: Sequelize.BIGINT, | ||
12 | allowNull: false, | ||
13 | defaultValue: -1 | ||
14 | } | ||
15 | await utils.queryInterface.addColumn('user', 'videoQuotaDaily', data) | ||
16 | } | ||
17 | } | ||
18 | |||
19 | function down (options) { | ||
20 | throw new Error('Not implemented.') | ||
21 | } | ||
22 | |||
23 | export { up, down } | ||