41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
exports = module.exports = {
|
|
getConfig,
|
|
|
|
prepareLocation,
|
|
changeLocation
|
|
};
|
|
|
|
const AuditSource = require('../auditsource.js'),
|
|
BoxError = require('../boxerror.js'),
|
|
dashboard = require('../dashboard.js'),
|
|
HttpError = require('connect-lastmile').HttpError,
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
|
safe = require('safetydance');
|
|
|
|
async function getConfig(req, res, next) {
|
|
const [error, cloudronConfig] = await safe(dashboard.getConfig());
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
next(new HttpSuccess(200, cloudronConfig));
|
|
}
|
|
|
|
async function prepareLocation(req, res, next) {
|
|
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
|
|
|
const [error, taskId] = await safe(dashboard.prepareLocation(req.body.domain, AuditSource.fromRequest(req)));
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
next(new HttpSuccess(202, { taskId }));
|
|
}
|
|
|
|
async function changeLocation(req, res, next) {
|
|
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
|
|
|
const [error] = await safe(dashboard.changeLocation(req.body.domain, AuditSource.fromRequest(req)));
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
next(new HttpSuccess(204, {}));
|
|
}
|