First version of the dbQuotaMiddleware
This commit is contained in:
parent
ea46db5923
commit
7e54912ee4
@ -6,6 +6,7 @@ const authorizationMiddleware = require('../middlewares/authorization');
|
||||
const connectionParamsMiddleware = require('../middlewares/connection-params');
|
||||
const { initializeProfilerMiddleware } = require('../middlewares/profiler');
|
||||
const rateLimitsMiddleware = require('../middlewares/rate-limit');
|
||||
const dbQuotaMiddleware = require('../middlewares/db-quota');
|
||||
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware;
|
||||
const errorHandlerFactory = require('../services/error_handler_factory');
|
||||
const StreamCopy = require('../services/stream_copy');
|
||||
@ -31,6 +32,7 @@ CopyController.prototype.route = function (app) {
|
||||
authorizationMiddleware(this.metadataBackend),
|
||||
connectionParamsMiddleware(this.userDatabaseService),
|
||||
validateCopyQuery(),
|
||||
dbQuotaMiddleware(),
|
||||
handleCopyFrom(this.logger),
|
||||
errorHandler(),
|
||||
errorMiddleware()
|
||||
|
21
app/middlewares/db-quota.js
Normal file
21
app/middlewares/db-quota.js
Normal file
@ -0,0 +1,21 @@
|
||||
const PSQL = require('cartodb-psql');
|
||||
|
||||
module.exports = function dbQuota () {
|
||||
return function dbQuotaMiddleware (req, res, next) {
|
||||
const { userDbParams } = res.locals;
|
||||
const pg = new PSQL(userDbParams);
|
||||
pg.connect((err, client, done) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
client.query('SELECT _CDB_UserQuotaInBytes() - CDB_UserDataSize(current_schema())', (err, res) => {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
console.warn(res);
|
||||
done();
|
||||
next();
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue
Block a user