Add option to pass cache bust param (#3525)

Co-authored-by: Dan Sullivan <dan@symbiosgroup.co.uk>
Co-authored-by: Frank Elsinga <frank@elsinga.de>
pull/5053/head
Dan Sullivan 2024-08-24 21:57:31 +01:00 committed by GitHub
parent 4cb264afca
commit dc3ad88fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 0 deletions

View File

@ -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");
});
};

View File

@ -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);

View File

@ -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;

View File

@ -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",

View File

@ -564,6 +564,18 @@
</label>
</div>
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' " class="my-3 form-check">
<input id="cache-bust" v-model="monitor.cacheBust" class="form-check-input" type="checkbox" value="">
<label class="form-check-label" for="cache-bust">
<i18n-t tag="label" keypath="cacheBusterParam" class="form-check-label" for="cache-bust">
<code>uptime_kuma_cachebuster</code>
</i18n-t>
</label>
<div class="form-text">
{{ $t("cacheBusterParamDescription") }}
</div>
</div>
<div class="my-3 form-check">
<input id="upside-down" v-model="monitor.upsideDown" class="form-check-input" type="checkbox">
<label class="form-check-label" for="upside-down">
@ -1018,6 +1030,7 @@ const monitorDefaults = {
kafkaProducerSaslOptions: {
mechanism: "None",
},
cacheBust: false,
kafkaProducerSsl: false,
kafkaProducerAllowAutoTopicCreation: false,
gamedigGivenPortOnly: true,