From 8bd92379514c16a26e4e344b3f62c4e93b2e65ac Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 26 Nov 2018 14:49:50 +0100 Subject: [PATCH] Use addon log routes in logviewer --- src/js/client.js | 12 ++++++++++++ src/js/logs.js | 16 ++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/js/client.js b/src/js/client.js index e739f3502..2f71f1942 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -653,6 +653,18 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N } }; + Client.prototype.getAddonLogs = function (addonName, follow, lines, callback) { + if (follow) { + var eventSource = new EventSource(client.apiOrigin + '/api/v1/addons/' + addonName + '/logstream?lines=' + lines + '&access_token=' + token); + callback(null, eventSource); + } else { + get('/api/v1/addons/' + addonName + '/logs?lines=100').success(function (data, status) { + if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); + callback(null, data); + }).error(defaultErrorHandler(callback)); + } + }; + Client.prototype.getApps = function (callback) { get('/api/v1/apps').success(function (data, status) { if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data)); diff --git a/src/js/logs.js b/src/js/logs.js index a3dd62604..be6338abd 100644 --- a/src/js/logs.js +++ b/src/js/logs.js @@ -32,7 +32,11 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f function showLogs() { if (!$scope.selected) return; - var func = $scope.selected.type === 'platform' ? Client.getPlatformLogs : Client.getAppLogs; + var func; + if ($scope.selected.type === 'platform') func = Client.getPlatformLogs; + else if ($scope.selected.type === 'addon') func = Client.getAddonLogs; + else func = Client.getAppLogs; + func($scope.selected.value, true, $scope.lines, function handleLogs(error, result) { if (error) return console.error(error); @@ -66,11 +70,11 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f { name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs/box') }, { name: 'Mail', type: 'platform', value: 'mail', url: Client.makeURL('/api/v1/cloudron/logs/mail') }, { name: 'Backup', type: 'platform', value: 'backup', url: Client.makeURL('/api/v1/cloudron/logs/backup') }, - { name: 'MongoDB', type: 'platform', value: 'mongodb', url: Client.makeURL('/api/v1/addons/mongodb/logs') }, - { name: 'MySQL', type: 'platform', value: 'mysql', url: Client.makeURL('/api/v1/addons/mysql/logs') }, - { name: 'PostgreSQL', type: 'platform', value: 'postgresql', url: Client.makeURL('/api/v1/addons/postgresql/logs') }, - { name: 'Email', type: 'platform', value: 'email', url: Client.makeURL('/api/v1/addons/email/logs') }, - { name: 'Docker', type: 'platform', value: 'docker', url: Client.makeURL('/api/v1/addons/docker/logs') } + { name: 'MongoDB', type: 'addon', value: 'mongodb', url: Client.makeURL('/api/v1/addons/mongodb/logs') }, + { name: 'MySQL', type: 'addon', value: 'mysql', url: Client.makeURL('/api/v1/addons/mysql/logs') }, + { name: 'PostgreSQL', type: 'addon', value: 'postgresql', url: Client.makeURL('/api/v1/addons/postgresql/logs') }, + { name: 'Email', type: 'addon', value: 'email', url: Client.makeURL('/api/v1/addons/email/logs') }, + { name: 'Docker', type: 'addon', value: 'docker', url: Client.makeURL('/api/v1/addons/docker/logs') } ]; $scope.selected = BUILT_IN_LOGS.find(function (e) { return e.value === id; });