Skip to content

Commit

Permalink
Add content purge filter
Browse files Browse the repository at this point in the history
* This filter can be added in case ALL content in a certain
time range needs to be purged.
* Fixes CI problems
  • Loading branch information
Petr Pchelko authored and johngian committed Jan 25, 2024
1 parent 81218db commit 7da9fb1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/purge_content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const mwUtil = require('./mwUtil');

module.exports = (hyper, req, next, options) => {
const startTime = Date.parse(options.start_time);
const endTime = Date.parse(options.end_time);

return next(hyper, req)
.then((res) => {
if (!startTime || !endTime) {
return res;
}

const contentTimestamp = mwUtil.extractDateFromEtag(res.headers.etag);
if (!contentTimestamp || contentTimestamp < startTime || contentTimestamp > endTime) {
return res;
}

if (mwUtil.isNoCacheRequest(req)) {
return res;
}

req.headers['cache-control'] = 'no-cache';
return next(hyper, req);
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"eslint-plugin-jsdoc": "^20.4.0",
"eslint-plugin-json": "^1.4.0",
"js-yaml": "^3.13.1",
"jsonc-parser": "3.2.0",
"mocha": "^6.2.3",
"mocha-lcov-reporter": "^1.3.0",
"mocha.parallel": "^0.15.6",
Expand Down
2 changes: 1 addition & 1 deletion test/features/pagecontent/language_variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Language variants', function() {
assert.deepEqual(res.headers['content-language'], 'de');
assert.deepEqual(res.headers['x-restbase-sunset'] || null, 'true');
assert.checkString(res.headers.etag, /^"\d+\/[a-f0-9-]+"$/);
assert.deepEqual(res.body.extract, 'Das ist eine testseite');
assert.deepEqual(res.body.extract, 'Das ist eine testseite!');
})
});

Expand Down

0 comments on commit 7da9fb1

Please sign in to comment.