settings: move dynamic dns to network

and add tests
This commit is contained in:
Girish Ramakrishnan
2023-08-02 22:53:29 +05:30
parent fccc2d04a9
commit a19e502198
9 changed files with 111 additions and 43 deletions
+22 -1
View File
@@ -5,7 +5,10 @@ exports = module.exports = {
setBlocklist,
getTrustedIps,
setTrustedIps
setTrustedIps,
getDynamicDns,
setDynamicDns
};
const assert = require('assert'),
@@ -54,3 +57,21 @@ async function setTrustedIps(req, res, next) {
next(new HttpSuccess(200, {}));
}
async function getDynamicDns(req, res, next) {
const [error, enabled] = await safe(network.getDynamicDns());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { enabled }));
}
async function setDynamicDns(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled boolean is required'));
const [error] = await safe(network.setDynamicDns(req.body.enabled));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
}