Commit bf7bf167 authored by Caillat Michel's avatar Caillat Michel
Browse files

require dirs and schedule the removal of temporary FITS files created for SAMP once every minute

parent 2c43c27e
...@@ -4,6 +4,7 @@ var favicon = require('serve-favicon'); ...@@ -4,6 +4,7 @@ var favicon = require('serve-favicon');
var logger = require('morgan'); var logger = require('morgan');
var cookieParser = require('cookie-parser'); var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser'); var bodyParser = require('body-parser');
var fs = require('fs');
var index = require('./routes/index'); var index = require('./routes/index');
var users = require('./routes/users'); var users = require('./routes/users');
...@@ -12,9 +13,9 @@ var connectArtemix = require('./routes/connectArtemix') ...@@ -12,9 +13,9 @@ var connectArtemix = require('./routes/connectArtemix')
var fitsBrowser = require('./routes/fitsBrowser'); var fitsBrowser = require('./routes/fitsBrowser');
var monitor = require('./routes/monitor'); var monitor = require('./routes/monitor');
var purge = require('./routes/purge'); var purge = require('./routes/purge');
const dirs = require('./dirs');
var app = express(); var app = express();
var yafits_samp = process.env.YAFITS_SAMPDIR;
// view engine setup // view engine setup
app.set('views', path.join(__dirname, 'views')); app.set('views', path.join(__dirname, 'views'));
...@@ -28,7 +29,7 @@ app.use(bodyParser.urlencoded({ extended: false })); ...@@ -28,7 +29,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'png'))); app.use(express.static(path.join(__dirname, 'png')));
app.use('"'+yafits_samp+'"', express.static(path.join(__dirname, '"'+yafits_samp+'"'))); app.use('"'+dirs.SAMP_DIR+'"', express.static(path.join(__dirname, '"'+dirs.SAMP_DIR+'"')));
app.use(function(req, res, next) { app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Origin", "*");
...@@ -67,5 +68,17 @@ app.use(function(err, req, res, next) { ...@@ -67,5 +68,17 @@ app.use(function(err, req, res, next) {
res.render('error'); res.render('error');
}); });
// SAMP_DIR cleaning of temporary FITS files scheduled
let regex1 = /spectrum\.[a-f0-9\-]+\.fits$/;
let regex2 = /averageSpectrum\.[a-f0-9\-]+\.fits$/;
function clearSAMPFITSFiles() {
console.log("About to clean spectrum and averageSpectrum FITS files found in " + dirs.SAMP_DIR);
fs.readdirSync(dirs.SAMP_DIR).filter(f => regex1.test(f)).map(f => fs.unlinkSync(dirs.SAMP_DIR+"/"+f));
fs.readdirSync(dirs.SAMP_DIR).filter(f => regex2.test(f)).map(f => fs.unlinkSync(dirs.SAMP_DIR+"/"+f));
}
setInterval(clearSAMPFITSFiles, 60000);
console.log("Ready to serve!"); console.log("Ready to serve!");
module.exports = app; module.exports = app;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment