From 4bef4aa26968f51efeb14cdbd543ec64acdec6e9 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Tue, 2 Jan 2024 00:33:00 +0530 Subject: [PATCH] purger: support page param and add validation !restart --- eventstream-router/routes/purger.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/eventstream-router/routes/purger.ts b/eventstream-router/routes/purger.ts index 130f40b..c18e962 100644 --- a/eventstream-router/routes/purger.ts +++ b/eventstream-router/routes/purger.ts @@ -103,11 +103,13 @@ export default class Purger extends Route { const existingEntries = Object.fromEntries( [...this.scheduledPurges.keys()].map(e => [e.serialize(), e]) ); - return new Set(entries.map(e => { - const entry = new PurgeEntry(e); - // return reference to existing entry if present, as that facilitates easy setDifference - return existingEntries[entry.serialize()] ?? entry; - })); + const parsedEntries = entries.map(e => new PurgeEntry(e)) + // filter out invalid ones + .filter(e => e.page) + // use reference to existing entry if present, as that facilitates easy setDifference + .map(e => existingEntries[e.serialize()] ?? e); + + return new Set(parsedEntries); } } @@ -118,8 +120,12 @@ class PurgeEntry { forceLinkUpdate: boolean forceRecursiveLinkUpdate: boolean constructor(entry: Template) { + const pageParam = entry.getParam(1) || entry.getParam('page'); + if (!pageParam) { + return; + } // strip link syntax from page name, maybe generated due to database report - this.page = entry.getParam(1).value.replace(/^\s*\[\[(.*?)\]\]\s*$/, '$1'); + this.page = pageParam.value.replace(/^\s*\[\[(.*?)\]\]\s*$/, '$1'); this.intervalDays = parseInt(entry.getParam('interval')?.value); // any non-empty value represents true!