2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2023-08-10 18:45:27 +05:30
|
|
|
getStatus,
|
2023-08-04 13:41:13 +05:30
|
|
|
|
2023-08-10 16:20:33 +05:30
|
|
|
listLanguages,
|
2023-08-04 10:10:08 +05:30
|
|
|
getLanguage,
|
|
|
|
|
setLanguage,
|
2023-08-04 13:41:13 +05:30
|
|
|
|
2023-08-04 10:10:08 +05:30
|
|
|
getTimeZone,
|
|
|
|
|
setTimeZone
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2025-08-14 11:17:38 +05:30
|
|
|
const assert = require('node:assert'),
|
2019-10-22 14:06:19 -07:00
|
|
|
BoxError = require('../boxerror.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
cloudron = require('../cloudron.js'),
|
2025-07-10 11:00:31 +02:00
|
|
|
HttpError = require('@cloudron/connect-lastmile').HttpError,
|
|
|
|
|
HttpSuccess = require('@cloudron/connect-lastmile').HttpSuccess,
|
2021-06-04 09:28:40 -07:00
|
|
|
safe = require('safetydance'),
|
2024-07-05 12:45:23 +02:00
|
|
|
translations = require('../translations.js');
|
2020-02-05 15:04:57 +01:00
|
|
|
|
2023-08-10 18:45:27 +05:30
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 16:20:33 +05:30
|
|
|
async function listLanguages(req, res, next) {
|
2024-07-05 12:45:23 +02:00
|
|
|
const [error, languages] = await safe(translations.listLanguages());
|
2021-08-19 11:00:35 -07:00
|
|
|
if (error) return next(new BoxError.toHttpError(error));
|
2020-11-18 00:10:06 +01:00
|
|
|
|
2021-08-19 11:00:35 -07:00
|
|
|
next(new HttpSuccess(200, { languages }));
|
2020-11-18 00:10:06 +01:00
|
|
|
}
|
2021-02-24 18:42:39 -08:00
|
|
|
|
2023-08-04 10:10:08 +05:30
|
|
|
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, {}));
|
|
|
|
|
}
|