Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Caillat Michel
yafits
Commits
bf7bf167
Commit
bf7bf167
authored
Jan 22, 2020
by
Caillat Michel
Browse files
require dirs and schedule the removal of temporary FITS files created for SAMP once every minute
parent
2c43c27e
Changes
1
Hide whitespace changes
Inline
Side-by-side
yafitsv/app.js
View file @
bf7bf167
...
...
@@ -4,6 +4,7 @@ var favicon = require('serve-favicon');
var
logger
=
require
(
'
morgan
'
);
var
cookieParser
=
require
(
'
cookie-parser
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
var
fs
=
require
(
'
fs
'
);
var
index
=
require
(
'
./routes/index
'
);
var
users
=
require
(
'
./routes/users
'
);
...
...
@@ -12,9 +13,9 @@ var connectArtemix = require('./routes/connectArtemix')
var
fitsBrowser
=
require
(
'
./routes/fitsBrowser
'
);
var
monitor
=
require
(
'
./routes/monitor
'
);
var
purge
=
require
(
'
./routes/purge
'
);
const
dirs
=
require
(
'
./dirs
'
);
var
app
=
express
();
var
yafits_samp
=
process
.
env
.
YAFITS_SAMPDIR
;
// view engine setup
app
.
set
(
'
views
'
,
path
.
join
(
__dirname
,
'
views
'
));
...
...
@@ -28,7 +29,7 @@ app.use(bodyParser.urlencoded({ extended: false }));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
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
)
{
res
.
header
(
"
Access-Control-Allow-Origin
"
,
"
*
"
);
...
...
@@ -67,5 +68,17 @@ app.use(function(err, req, res, next) {
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!
"
);
module
.
exports
=
app
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment