Merge pull request #4124 from cp2004/improve/disable-cache-buster

✨  Add option to disable cache busting on webcam URL
This commit is contained in:
Gina Häußge authored and GitHub committed 2021-05-04 18:23:51 +02:00
commit 0ce1c0537c
7 files changed
+27 -6

No files matched your search

+3
View File
@@ -139,6 +139,7 @@ def getSettings():
"flipH": s.getBoolean(["webcam", "flipH"]),
"flipV": s.getBoolean(["webcam", "flipV"]),
"rotate90": s.getBoolean(["webcam", "rotate90"]),
"cacheBuster": s.getBoolean(["webcam", "cacheBuster"]),
},
"feature": {
"temperatureGraph": s.getBoolean(["feature", "temperatureGraph"]),
@@ -593,6 +594,8 @@ def _saveSettings(data):
s.setBoolean(["webcam", "flipV"], data["webcam"]["flipV"])
if "rotate90" in data["webcam"]:
s.setBoolean(["webcam", "rotate90"], data["webcam"]["rotate90"])
if "cacheBuster" in data["webcam"]:
s.setBoolean(["webcam", "cacheBuster"], data["webcam"]["cacheBuster"])
if "feature" in data:
if "temperatureGraph" in data["feature"]:
+1
View File
@@ -265,6 +265,7 @@ default_settings = {
"fps": 25,
},
"cleanTmpAfterDays": 7,
"cacheBuster": False,
},
"gcodeAnalysis": {
"maxExtruders": 10,
@@ -693,12 +693,14 @@ $(function () {
var newSrc = self.settings.webcam_streamUrl();
if (currentSrc != newSrc) {
if (newSrc.lastIndexOf("?") > -1) {
newSrc += "&";
} else {
newSrc += "?";
if (self.settings.webcam_cacheBuster()) {
if (newSrc.lastIndexOf("?") > -1) {
newSrc += "&";
} else {
newSrc += "?";
}
newSrc += new Date().getTime();
}
newSrc += new Date().getTime();
self.webcamLoaded(false);
self.webcamError(false);
@@ -165,6 +165,7 @@ $(function () {
self.webcam_flipH = ko.observable(undefined);
self.webcam_flipV = ko.observable(undefined);
self.webcam_rotate90 = ko.observable(undefined);
self.webcam_cacheBuster = ko.observable(undefined);
self.feature_temperatureGraph = ko.observable(undefined);
self.feature_sdSupport = ko.observable(undefined);
@@ -14,6 +14,7 @@
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '.form-horizontal', container: '.hide' }"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
{% include "snippets/settings/webcam/webcamStreamTimeout.jinja2" %}
{% include "snippets/settings/webcam/webcamCacheBuster.jinja2" %}
</div>
</div>
</form>
@@ -0,0 +1,13 @@
<div class="control-group" title="{{ _('Enable the cache buster on the webcam URl')|edq }}">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: webcam_cacheBuster" id="settings-webcamCacheBuster">
{{ _('Enable Cache buster') }}
<span class="help-block">
<span class="label label-warning">{{ _("Warning") }}</span>
{{ _("This may cause unpredictable caching behaviour. Only disable if your webcam server is incompatible and does not work in OctoPrint's UI") }}
</span>
</label>
</div>
</div>
@@ -5,6 +5,6 @@
<input type="text" class="input-block-level" data-bind="value: webcam_streamUrl, valueUpdate: 'afterkeydown'" id="settings-webcamStreamUrl">
<button class="btn" type="button" data-bind="click: testWebcamStreamUrl, enable: webcam_streamUrl() && !testWebcamStreamUrlBusy(), css: {disabled: !webcam_streamUrl() || testWebcamStreamUrlBusy()}"><i class="fas fa-spinner fa-spin" data-bind="visible: testWebcamStreamUrlBusy"></i> {{ _('Test') }}</button>
</div>
<span class="help-inline">{% trans %}Needs to be reachable from the browser displaying the OctoPrint UI, used to embed the webcam stream into the page.{% endtrans %}</span>
<span class="help-block">{% trans %}Needs to be reachable from the browser displaying the OctoPrint UI, used to embed the webcam stream into the page.{% endtrans %}</span>
</div>
</div>