2022-03-28 19:49:56 +02:00
|
|
|
let runtimeAPI;
|
|
|
|
let settings;
|
|
|
|
const apiUtil = require("../util");
|
2022-03-24 17:00:45 +01:00
|
|
|
module.exports = {
|
2022-03-28 19:49:56 +02:00
|
|
|
init: function(_settings, _runtimeAPI) {
|
|
|
|
settings = _settings;
|
2022-03-24 17:00:45 +01:00
|
|
|
runtimeAPI = _runtimeAPI;
|
|
|
|
},
|
2022-03-28 19:49:56 +02:00
|
|
|
getReport: function(req, res) {
|
2022-03-29 21:48:29 +02:00
|
|
|
const diagnosticsOpts = settings.diagnostics || {};
|
2022-03-28 19:49:56 +02:00
|
|
|
const opts = {
|
2022-03-24 17:00:45 +01:00
|
|
|
user: req.user,
|
2022-03-29 21:48:29 +02:00
|
|
|
scope: diagnosticsOpts.level || "basic"
|
2022-03-24 17:00:45 +01:00
|
|
|
}
|
2022-03-29 21:48:29 +02:00
|
|
|
if(diagnosticsOpts.enabled === false || diagnosticsOpts.enabled === "false") {
|
2022-04-06 16:11:03 +02:00
|
|
|
apiUtil.rejectHandler(req, res, {message: "diagnostics are disabled", status: 403, code: "diagnostics.disabled" })
|
2022-03-28 19:49:56 +02:00
|
|
|
} else {
|
|
|
|
runtimeAPI.diagnostics.get(opts)
|
|
|
|
.then(function(result) { res.json(result); })
|
|
|
|
.catch(err => apiUtil.rejectHandler(req, res, err))
|
2022-03-24 17:00:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|