settingsdb: merge blob get/set into settings.js
This commit is contained in:
+11
-13
@@ -88,30 +88,28 @@ function getAppstoreListingConfig(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function setCloudronAvatar(req, res, next) {
|
||||
async function setCloudronAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.files, 'object');
|
||||
|
||||
if (!req.files.avatar) return next(new HttpError(400, 'avatar must be provided'));
|
||||
const avatar = safe.fs.readFileSync(req.files.avatar.path);
|
||||
if (!avatar) return next(500, safe.error.message);
|
||||
|
||||
settings.setCloudronAvatar(avatar, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(settings.setCloudronAvatar(avatar));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
function getCloudronAvatar(req, res, next) {
|
||||
settings.getCloudronAvatar(function (error, avatar) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getCloudronAvatar(req, res, next) {
|
||||
const [error, avatar] = await safe(settings.getCloudronAvatar());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
// avoid caching the avatar on the client to see avatar changes immediately
|
||||
res.set('Cache-Control', 'no-cache');
|
||||
// avoid caching the avatar on the client to see avatar changes immediately
|
||||
res.set('Cache-Control', 'no-cache');
|
||||
|
||||
res.set('Content-Type', 'image/png');
|
||||
res.status(200).send(avatar);
|
||||
});
|
||||
res.set('Content-Type', 'image/png');
|
||||
res.status(200).send(avatar);
|
||||
}
|
||||
|
||||
function get(req, res, next) {
|
||||
|
||||
+11
-12
@@ -5,31 +5,30 @@ exports = module.exports = {
|
||||
setBlocklist
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
const assert = require('assert'),
|
||||
auditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
network = require('../network.js');
|
||||
network = require('../network.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
function getBlocklist(req, res, next) {
|
||||
network.getBlocklist(function (error, blocklist) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getBlocklist(req, res, next) {
|
||||
const [error, blocklist] = await safe(network.getBlocklist());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { blocklist }));
|
||||
});
|
||||
next(new HttpSuccess(200, { blocklist }));
|
||||
}
|
||||
|
||||
function setBlocklist(req, res, next) {
|
||||
async function setBlocklist(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.blocklist !== 'string') return next(new HttpError(400, 'blocklist must be a string'));
|
||||
|
||||
req.clearTimeout(); // can take a while if there is a lot of network ranges
|
||||
|
||||
network.setBlocklist(req.body.blocklist, auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(network.setBlocklist(req.body.blocklist, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user