settings: move language and tz into cloudron.js

This commit is contained in:
Girish Ramakrishnan
2023-08-04 10:10:08 +05:30
parent ec23c7d2b8
commit 775246946a
13 changed files with 246 additions and 165 deletions
+42 -1
View File
@@ -22,7 +22,12 @@ exports = module.exports = {
syncDnsRecords,
getSystemGraphs,
getPlatformStatus,
getBlockDevices
getBlockDevices,
getLanguage,
setLanguage,
getTimeZone,
setTimeZone
};
const assert = require('assert'),
@@ -318,3 +323,39 @@ async function getBlockDevices(req, res, next) {
next(new HttpSuccess(200, { devices }));
}
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, {}));
}