32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
exports = module.exports = {
|
|
getRemoteSupport,
|
|
enableRemoteSupport,
|
|
};
|
|
|
|
const assert = require('assert'),
|
|
AuditSource = require('../auditsource.js'),
|
|
HttpError = require('@cloudron/connect-lastmile').HttpError,
|
|
HttpSuccess = require('@cloudron/connect-lastmile').HttpSuccess,
|
|
safe = require('safetydance'),
|
|
support = require('../support.js');
|
|
|
|
async function enableRemoteSupport(req, res, next) {
|
|
assert.strictEqual(typeof req.body, 'object');
|
|
|
|
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled is required'));
|
|
|
|
const [error] = await safe(support.enableRemoteSupport(req.body.enabled, AuditSource.fromRequest(req)));
|
|
if (error) return next(new HttpError(503, 'Error enabling remote support. Try running "cloudron-support --enable-remote-support" on the server'));
|
|
|
|
next(new HttpSuccess(202, {}));
|
|
}
|
|
|
|
async function getRemoteSupport(req, res, next) {
|
|
const [error, enabled] = await safe(support.getRemoteSupport());
|
|
if (error) return next(new HttpError(500, error));
|
|
|
|
next(new HttpSuccess(200, { enabled }));
|
|
}
|