Prevent dupliate callbacks

This commit is contained in:
Tim Van Baak 2021-03-17 20:59:31 -07:00
parent 5d0c5b1ae3
commit 8e2369eff9
2 changed files with 4 additions and 2 deletions

View File

@ -176,6 +176,7 @@ def callback():
params = request.get_json() params = request.get_json()
if 'source' not in params and 'itemid' not in params: if 'source' not in params and 'itemid' not in params:
logger.error("Bad request params: {}".format(params)) logger.error("Bad request params: {}".format(params))
logger.info('Executing callback for {}/{}'.format(params['source'], params['itemid']))
sources.item_callback(params['source'], params['itemid']) sources.item_callback(params['source'], params['itemid'])
return jsonify({}) return jsonify({})

View File

@ -76,10 +76,11 @@
body: JSON.stringify({items: items}), body: JSON.stringify({items: items}),
}) })
.then(function () { .then(function () {
location.reload() location.reload();
}); });
}; };
var callback = function (source, itemid) { var callback = function (source, itemid) {
document.getElementById(source + "-" + itemid + "-callback").disabled = true;
fetch('/callback/', { fetch('/callback/', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -107,7 +108,7 @@
<p>{{item.body|safe}}</p> <p>{{item.body|safe}}</p>
{% endif %} {% endif %}
{% if item.callback %} {% if item.callback %}
<p><button onclick="javascript:callback('{{item.source}}', '{{item.id}}')">Callback</button></p> <p><button id="{{item.source}}-{{item.id}}-callback" onclick="javascript:callback('{{item.source}}', '{{item.id}}')">Callback</button></p>
{% endif %} {% endif %}
</details> </details>
{% else %}<span class="item-title">{{item.title}}</span><br> {% else %}<span class="item-title">{{item.title}}</span><br>