diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index ac82b8a..7e04a54 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -4,6 +4,15 @@ var http = require('http').Server(app); var https = require('https'); var io = require('socket.io')(http); +var chokidar = require("chokidar"); +var logpath = "/var/lab/playground-serverlogs"; +var watcher = chokidar.watch(logpath, { + ignored: /[\/\\]\./, + awaitWriteFinish: true, + persistent: true + }); + + var async = require("async"); const { check, validationResult } = require('express-validator'); const urlExistSync = require("url-exist-sync"); @@ -104,6 +113,91 @@ function convertDateToUTC(date) { return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(),date.getUTCMilliseconds()); } +// *************************************************** +// get pipelines +// *************************************************** + +async function getpipelines(token) { + const agent = new https.Agent({ + rejectUnauthorized: false, + }); + const instance = axios.create({ + baseURL: 'https://api.swarmlab.io', + withCredentials: true, + rejectUnauthorized: false, + crossdomain: true, + httpsAgent: agent, + headers: { + 'Accept': 'application/json', + 'Content-Type': 'multipart/form-data', + 'Authorization': 'Bearer '+token + } + }) + try { + var pipelines = { + "source":'ssologin' + } + var params = { + pipeline: pipelines + } + + var options = { + headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, + }; + + //https://api.swarmlab.io/gettutorlabrooms?sort=pipelinename%7Casc&page=1&per_page=5&filter=&type=scripts&tutor=yes + instance.defaults.timeout = 30000; + const res = await instance.get('/gettutorlabrooms',params,options); + if(res.status == 200){ + return res.data + }else{ + console.log("noerror: " + res) + return res.status + + } + } + catch (err) { + console.error("error: "+err); + var error = new Object(); + error.action = '401' + return error + } +} + + +global.online='ob'; + + function onWatcherReady(){ + console.info('From here can you check for real changes, the initial scan has been completed.'); + } + + // Declare the listeners of the watcher + watcher + .on('add', function(path) { + console.log('File', path, 'has been added'); + }) + .on('addDir', function(path) { + console.log('Directory', path, 'has been added'); + }) + .on('change', function(path) { + console.log('File', path, 'has been changed'); + }) + .on('unlink', function(path) { + console.log('File', path, 'has been removed'); + }) + .on('unlinkDir', function(path) { + console.log('Directory', path, 'has been removed'); + }) + .on('error', function(error) { + console.log('Error happened', error); + }) + .on('ready', onWatcherReady) + .on('raw', function(event, path, details) { + // This event should be triggered everytime something happens. + console.log('Raw event info:', event, path, details); + }); + + // *************************************************** // rest get // ***************************************************