A free, self-hostable news aggregator…
Custom favicons async/await (#8182)
Alexandre Alapetite0587ccaff844
diff --git a/p/scripts/extra.js b/p/scripts/extra.jsindex 2e956d6db..96874a65d 100644--- a/p/scripts/extra.js+++ b/p/scripts/extra.js@@ -249,26 +249,27 @@ function init_update_feed() {});if (faviconExtBtn) {- faviconExtBtn.onclick = function (e) {+ faviconExtBtn.onclick = async function (e) {e.preventDefault();faviconExtBtn.disabled = true;- fetch(faviconExtBtn.dataset.extensionUrl, {- method: 'POST',- headers: {- 'Content-Type': 'application/json; charset=utf-8'- },- body: JSON.stringify({- '_csrf': context.csrf,- 'extAction': 'query_icon_info',- 'id': +feed_update.dataset.feedId- }),- }).then(resp => {+ try {+ const resp = await fetch(faviconExtBtn.dataset.extensionUrl, {+ method: 'POST',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json; charset=UTF-8',+ },+ body: JSON.stringify({+ '_csrf': context.csrf,+ 'extAction': 'query_icon_info',+ 'id': +feed_update.dataset.feedId+ }),+ });if (!resp.ok) {faviconExtBtn.disabled = false;- return Promise.reject(resp);+ throw new Error(`Custom favicons HTTP error ${resp.status}: ${resp.statusText}`);}- return resp.json();- }).then(json => {+ const json = await resp.json();clearUploadedIcon();const resetField = feed_update.querySelector('input[name="resetFavicon"]');if (resetField) {@@ -281,7 +282,9 @@ function init_update_feed() {extension.dataset.initialExt = extension.innerText;extension.innerText = json.extName;favicon.src = json.iconUrl;- });+ } catch (error) {+ faviconExtBtn.disabled = false;+ }};faviconExtBtn.form.onsubmit = async function (e) {const extChanged = faviconExtBtn.disabled;