diff --git a/src/routes/apps.js b/src/routes/apps.js index 56a2a0f49..06c8b16b3 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -40,6 +40,7 @@ exports = module.exports = { restart, exec, execWebSocket, + checkForUpdates, clone, @@ -57,6 +58,7 @@ const apps = require('../apps.js'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, safe = require('safetydance'), + updateChecker = require('../updatechecker.js'), users = require('../users.js'), WebSocket = require('ws'); @@ -801,6 +803,8 @@ async function setMounts(req, res, next) { } async function listEventlog(req, res, next) { + assert.strictEqual(typeof req.app, 'object'); + const page = typeof req.query.page !== 'undefined' ? parseInt(req.query.page) : 1; if (!page || page < 0) return next(new HttpError(400, 'page query param has to be a postive number')); @@ -812,3 +816,13 @@ async function listEventlog(req, res, next) { next(new HttpSuccess(200, { eventlogs })); } + +async function checkForUpdates(req, res, next) { + assert.strictEqual(typeof req.app, 'object'); + + // it can take a while sometimes to get all the app updates one by one + req.clearTimeout(); + + await updateChecker.checkForUpdates({ automatic: false }); // appId argument is ignored for the moment + next(new HttpSuccess(200, { update: updateChecker.getUpdateInfo() })); +} diff --git a/src/server.js b/src/server.js index 4470ff33c..095af0c53 100644 --- a/src/server.js +++ b/src/server.js @@ -221,6 +221,7 @@ function initializeExpressSync() { router.post('/api/v1/apps/:id/configure/location', json, token, routes.apps.load, authorizeAdmin, routes.apps.setLocation); router.post('/api/v1/apps/:id/configure/mounts', json, token, routes.apps.load, authorizeAdmin, routes.apps.setMounts); router.post('/api/v1/apps/:id/repair', json, token, routes.apps.load, authorizeOperator, routes.apps.repair); + router.post('/api/v1/apps/:id/check_for_updates', json, token, routes.apps.load, authorizeOperator, routes.apps.checkForUpdates); router.post('/api/v1/apps/:id/update', json, token, routes.apps.load, authorizeOperator, routes.apps.update); router.post('/api/v1/apps/:id/restore', json, token, routes.apps.load, authorizeOperator, routes.apps.restore); router.post('/api/v1/apps/:id/import', json, token, routes.apps.load, authorizeOperator, routes.apps.importApp); diff --git a/src/updatechecker.js b/src/updatechecker.js index 64afc55b0..0cbb0a65b 100644 --- a/src/updatechecker.js +++ b/src/updatechecker.js @@ -35,8 +35,8 @@ async function checkAppUpdates(options) { debug('checkAppUpdates: checking for updates'); - let state = getUpdateInfo(); - let newState = { }; // create new state so that old app ids are removed + const state = getUpdateInfo(); + const newState = { }; // create new state so that old app ids are removed const result = await apps.list(); @@ -64,7 +64,7 @@ async function checkBoxUpdates(options) { const updateInfo = await appstore.getBoxUpdate(options); - let state = getUpdateInfo(); + const state = getUpdateInfo(); if (!updateInfo) { // no update if ('box' in state) {