Files
cloudron-box/src/routes/cloudron.js
T
Girish Ramakrishnan 68a3c267e5 move config route under dashboard
it's essentially giving info for various parts of the ui
2023-08-12 22:25:49 +05:30

100 lines
3.1 KiB
JavaScript

'use strict';
exports = module.exports = {
getStatus,
updateDashboardDomain,
prepareDashboardDomain,
getPlatformStatus,
listLanguages,
getLanguage,
setLanguage,
getTimeZone,
setTimeZone
};
const assert = require('assert'),
AuditSource = require('../auditsource.js'),
BoxError = require('../boxerror.js'),
cloudron = require('../cloudron.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
platform = require('../platform.js'),
safe = require('safetydance'),
translation = require('../translation.js');
async function getStatus(req, res, next) {
const [error, status] = await safe(cloudron.getStatus());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, status));
}
async function updateDashboardDomain(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(cloudron.updateDashboardDomain(req.body.domain, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204, {}));
}
async function prepareDashboardDomain(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(cloudron.prepareDashboardDomain(req.body.domain, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, { taskId }));
}
async function listLanguages(req, res, next) {
const [error, languages] = await safe(translation.listLanguages());
if (error) return next(new BoxError.toHttpError(error));
next(new HttpSuccess(200, { languages }));
}
async function getPlatformStatus(req, res, next) {
next(new HttpSuccess(200, platform.getStatus()));
}
async function getTimeZone(req, res, next) {
const [error, timeZone] = await safe(cloudron.getTimeZone());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { timeZone }));
}
async function setTimeZone(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.timeZone !== 'string') return next(new HttpError(400, 'timeZone is required'));
const [error] = await safe(cloudron.setTimeZone(req.body.timeZone));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
}
async function getLanguage(req, res, next) {
const [error, language] = await safe(cloudron.getLanguage());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { language }));
}
async function setLanguage(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.language || typeof req.body.language !== 'string') return next(new HttpError(400, 'language is required'));
const [error] = await safe(cloudron.setLanguage(req.body.language));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
}