From dc3ad88fe1c9f1b2264206a87cb39f7e6ab63c78 Mon Sep 17 00:00:00 2001 From: Dan Sullivan Date: Sat, 24 Aug 2024 21:57:31 +0100 Subject: [PATCH] Add option to pass cache bust param (#3525) Co-authored-by: Dan Sullivan Co-authored-by: Frank Elsinga --- .../2024-08-24-000-add-cache-bust.js | 13 +++++++++++++ server/model/monitor.js | 17 +++++++++++++++++ server/server.js | 1 + src/lang/en.json | 2 ++ src/pages/EditMonitor.vue | 13 +++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 db/knex_migrations/2024-08-24-000-add-cache-bust.js diff --git a/db/knex_migrations/2024-08-24-000-add-cache-bust.js b/db/knex_migrations/2024-08-24-000-add-cache-bust.js new file mode 100644 index 000000000..3644377c4 --- /dev/null +++ b/db/knex_migrations/2024-08-24-000-add-cache-bust.js @@ -0,0 +1,13 @@ +exports.up = function (knex) { + return knex.schema + .alterTable("monitor", function (table) { + table.boolean("cache_bust").notNullable().defaultTo(false); + }); +}; + +exports.down = function (knex) { + return knex.schema + .alterTable("monitor", function (table) { + table.dropColumn("cache_bust"); + }); +}; diff --git a/server/model/monitor.js b/server/model/monitor.js index b929e705c..73901e807 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -159,6 +159,7 @@ class Monitor extends BeanModel { kafkaProducerAllowAutoTopicCreation: this.getKafkaProducerAllowAutoTopicCreation(), kafkaProducerMessage: this.kafkaProducerMessage, screenshot, + cacheBust: this.getCacheBust(), remote_browser: this.remote_browser, snmpOid: this.snmpOid, jsonPathOperator: this.jsonPathOperator, @@ -295,6 +296,14 @@ class Monitor extends BeanModel { return Boolean(this.grpcEnableTls); } + /** + * Parse to boolean + * @returns {boolean} if cachebusting is enabled + */ + getCacheBust() { + return Boolean(this.cacheBust); + } + /** * Get accepted status codes * @returns {object} Accepted status codes @@ -500,6 +509,14 @@ class Monitor extends BeanModel { options.data = bodyValue; } + if (this.cacheBust) { + const randomFloatString = Math.random().toString(36); + const cacheBust = randomFloatString.substring(2); + options.params = { + uptime_kuma_cachebuster: cacheBust, + }; + } + if (this.proxy_id) { const proxy = await R.load("proxy", this.proxy_id); diff --git a/server/server.js b/server/server.js index e96ff0181..c0a1422a8 100644 --- a/server/server.js +++ b/server/server.js @@ -826,6 +826,7 @@ let needSetup = false; bean.kafkaProducerAllowAutoTopicCreation = monitor.kafkaProducerAllowAutoTopicCreation; bean.kafkaProducerSaslOptions = JSON.stringify(monitor.kafkaProducerSaslOptions); bean.kafkaProducerMessage = monitor.kafkaProducerMessage; + bean.cacheBust = monitor.cacheBust; bean.kafkaProducerSsl = monitor.kafkaProducerSsl; bean.kafkaProducerAllowAutoTopicCreation = monitor.kafkaProducerAllowAutoTopicCreation; diff --git a/src/lang/en.json b/src/lang/en.json index 4cdda0582..c2e960d40 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -879,6 +879,8 @@ "nostrRecipientsHelp": "npub format, one per line", "showCertificateExpiry": "Show Certificate Expiry", "noOrBadCertificate": "No/Bad Certificate", + "cacheBusterParam": "Add the {0} parameter", + "cacheBusterParamDescription": "Randomly generated parameter to skip caches.", "gamedigGuessPort": "Gamedig: Guess Port", "gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.", "Bitrix24 Webhook URL": "Bitrix24 Webhook URL", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index fd2f3c72f..8318bb7aa 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -564,6 +564,18 @@ +
+ + +
+ {{ $t("cacheBusterParamDescription") }} +
+
+