Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to pass cache bust param #3525

Merged
merged 16 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions db/knex_migrations/2024-08-24-000-add-cache-bust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {

Check failure on line 3 in db/knex_migrations/2024-08-24-000-add-cache-bust.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected indentation of 8 spaces but found 4
table.boolean("cache_bust").notNullable().defaultTo(false);

Check failure on line 4 in db/knex_migrations/2024-08-24-000-add-cache-bust.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected indentation of 12 spaces but found 8
});

Check failure on line 5 in db/knex_migrations/2024-08-24-000-add-cache-bust.js

View workflow job for this annotation

GitHub Actions / check-linters

Expected indentation of 8 spaces but found 4

CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
};

exports.down = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.dropColumn("cache_bust");
});
};
17 changes: 17 additions & 0 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Monitor extends BeanModel {
kafkaProducerAllowAutoTopicCreation: this.getKafkaProducerAllowAutoTopicCreation(),
kafkaProducerMessage: this.kafkaProducerMessage,
screenshot,
cacheBust: this.getCacheBust(),
dansullivan86 marked this conversation as resolved.
Show resolved Hide resolved
remote_browser: this.remote_browser,
snmpOid: this.snmpOid,
jsonPathOperator: this.jsonPathOperator,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
dansullivan86 marked this conversation as resolved.
Show resolved Hide resolved
uptime_kuma_cachebuster: cacheBust,
};
}

if (this.proxy_id) {
const proxy = await R.load("proxy", this.proxy_id);

Expand Down
1 change: 1 addition & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -1018,6 +1030,7 @@ const monitorDefaults = {
kafkaProducerSaslOptions: {
mechanism: "None",
},
cacheBust: false,
kafkaProducerSsl: false,
kafkaProducerAllowAutoTopicCreation: false,
gamedigGivenPortOnly: true,
Expand Down
Loading