-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (39 loc) · 1.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* lastModified Plugin
* check freshness of the content
*/
var fs = require('fs');
var ejs = require('ejs');
var util = require('util');
var template = fs.readFileSync(__dirname + '/views/_detailsEdit.ejs', 'utf8');
exports.initWebApp = function(options) {
var dashboard = options.dashboard;
dashboard.on('populateFromDirtyCheck', function(checkDocument, dirtyCheck, type) {
if (type !== 'http' && type !== 'https') return;
var match = dirtyCheck.lastModified;
checkDocument.setPollerParam('lastModified', match);
});
dashboard.on('checkEdit', function(type, check, partial) {
if (type !== 'http' && type !== 'https') return;
check.lastModified = '';
var options = check.getPollerParam('lastModified');
if(options!=undefined)
check.setPollerParam('lastModified', options);
else
check.setPollerParam('lastModified', '');
partial.push(ejs.render(template, { locals: { check: check } }));
});
};
exports.initMonitor = function(options) {
options.monitor.on('pollerPolled', function(check, res, details) {
if (check.type !== 'http' && check.type !== 'https') return;
var lastModified = check.pollerParams && check.pollerParams.lastModified;
if (!lastModified) return;
dateFile=Date.parse( res.headers['last-modified']);
today=new Date().getTime();
if((today - dateFile) > lastModified*1000){
throw new Error("File is too old.");
}
return;
});
};