2023-08-12 21:47:24 +05:30
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
|
getConfig,
|
2023-08-13 10:06:01 +05:30
|
|
|
|
2023-08-14 09:40:31 +05:30
|
|
|
startPrepareLocation,
|
2023-08-17 13:02:36 +05:30
|
|
|
changeLocation
|
2023-08-12 21:47:24 +05:30
|
|
|
};
|
|
|
|
|
|
2023-08-13 10:06:01 +05:30
|
|
|
const AuditSource = require('../auditsource.js'),
|
|
|
|
|
BoxError = require('../boxerror.js'),
|
2023-08-16 19:28:04 +05:30
|
|
|
constants = require('../constants.js'),
|
2023-08-12 21:47:24 +05:30
|
|
|
dashboard = require('../dashboard.js'),
|
2023-08-13 10:06:01 +05:30
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
2023-08-12 21:47:24 +05:30
|
|
|
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));
|
|
|
|
|
}
|
2023-08-13 10:06:01 +05:30
|
|
|
|
2023-08-14 09:40:31 +05:30
|
|
|
async function startPrepareLocation(req, res, next) {
|
2023-08-13 10:06:01 +05:30
|
|
|
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
|
|
|
|
|
2023-08-14 09:40:31 +05:30
|
|
|
const [error, taskId] = await safe(dashboard.startPrepareLocation(req.body.domain, AuditSource.fromRequest(req)));
|
2023-08-13 10:06:01 +05:30
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(202, { taskId }));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 13:02:36 +05:30
|
|
|
async function changeLocation(req, res, next) {
|
2023-08-13 10:06:01 +05:30
|
|
|
if (!req.body.domain || typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string'));
|
|
|
|
|
|
2023-08-17 13:02:36 +05:30
|
|
|
const [error] = await safe(dashboard.changeLocation(constants.DASHBOARD_SUBDOMAIN, req.body.domain, AuditSource.fromRequest(req)));
|
2023-08-13 10:06:01 +05:30
|
|
|
if (error) return next(BoxError.toHttpError(error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(204, {}));
|
|
|
|
|
}
|