From c608a15a9c53a19654f5a36ba2056a7a1eb561da Mon Sep 17 00:00:00 2001 From: Daniel Nilsson Date: Wed, 28 Feb 2024 23:12:55 +0100 Subject: [PATCH] luci-app-attendedsysupgrade: don't reassign data and firmware info The reassignment of the variable that holds the package information once you get a response from the sysupgrade server caused the package list (which is only loaded once when entering the app) to become an array instead of an object (since that's how the response is structured), which gave the result of once cancelling the firmware upgrade, the package list is now an array, making the package list unusable. This commit updates the variables that shouldn't be changed (data and firmware) to constants and all handle methods to take these values as parameters instead, allowing us to avoid the possible reassignment which will otherwise result in unexpected control flows. Ref: #6284 Signed-off-by: Daniel Nilsson --- .../view/attendedsysupgrade/overview.js | 160 ++++++++---------- .../po/ar/attendedsysupgrade.po | 104 ++++++------ .../po/bg/attendedsysupgrade.po | 104 ++++++------ .../po/bn_BD/attendedsysupgrade.po | 104 ++++++------ .../po/ca/attendedsysupgrade.po | 104 ++++++------ .../po/cs/attendedsysupgrade.po | 104 ++++++------ .../po/da/attendedsysupgrade.po | 104 ++++++------ .../po/de/attendedsysupgrade.po | 104 ++++++------ .../po/el/attendedsysupgrade.po | 104 ++++++------ .../po/en/attendedsysupgrade.po | 104 ++++++------ .../po/es/attendedsysupgrade.po | 104 ++++++------ .../po/fa/attendedsysupgrade.po | 104 ++++++------ .../po/fi/attendedsysupgrade.po | 104 ++++++------ .../po/fr/attendedsysupgrade.po | 104 ++++++------ .../po/he/attendedsysupgrade.po | 104 ++++++------ .../po/hi/attendedsysupgrade.po | 104 ++++++------ .../po/hu/attendedsysupgrade.po | 104 ++++++------ .../po/it/attendedsysupgrade.po | 104 ++++++------ .../po/ja/attendedsysupgrade.po | 104 ++++++------ .../po/ko/attendedsysupgrade.po | 104 ++++++------ .../po/lt/attendedsysupgrade.po | 104 ++++++------ .../po/mr/attendedsysupgrade.po | 104 ++++++------ .../po/ms/attendedsysupgrade.po | 104 ++++++------ .../po/nb_NO/attendedsysupgrade.po | 104 ++++++------ .../po/nl/attendedsysupgrade.po | 104 ++++++------ .../po/pl/attendedsysupgrade.po | 104 ++++++------ .../po/pt/attendedsysupgrade.po | 104 ++++++------ .../po/pt_BR/attendedsysupgrade.po | 104 ++++++------ .../po/ro/attendedsysupgrade.po | 104 ++++++------ .../po/ru/attendedsysupgrade.po | 104 ++++++------ .../po/sk/attendedsysupgrade.po | 104 ++++++------ .../po/sv/attendedsysupgrade.po | 104 ++++++------ .../po/templates/attendedsysupgrade.pot | 104 ++++++------ .../po/tr/attendedsysupgrade.po | 104 ++++++------ .../po/uk/attendedsysupgrade.po | 104 ++++++------ .../po/vi/attendedsysupgrade.po | 104 ++++++------ .../po/zh_Hans/attendedsysupgrade.po | 104 ++++++------ .../po/zh_Hant/attendedsysupgrade.po | 104 ++++++------ 38 files changed, 1999 insertions(+), 2009 deletions(-) diff --git a/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js b/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js index 06bc1bb068..36b7c852cb 100644 --- a/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js +++ b/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js @@ -67,26 +67,10 @@ return view.extend({ building_image: [80, _('Generating firmware image')], }, - data: { - url: '', - revision: '', - advanced_mode: 0, - rebuilder: [], - sha256_unsigned: '', - }, - - firmware: { - profile: '', - target: '', - version: '', - packages: [], - diff_packages: true, - filesystem: '', - }, + request_hash: '', + sha256_unsigned: '', - selectImage: function (images) { - let firmware = this.firmware; - let data = this.data; + selectImage: function (images, data, firmware) { var filesystemFilter = function(e) { return (e.filesystem == firmware.filesystem); } @@ -105,13 +89,13 @@ return view.extend({ return images.filter(filesystemFilter).filter(typeFilter)[0]; }, - handle200: function (response) { + handle200: function (response, content, data, firmware) { response = response.json(); - let image = this.selectImage(response.images); + let image = this.selectImage(response.images, data, firmware); if (image.name != undefined) { - this.data.sha256_unsigned = image.sha256_unsigned; - let sysupgrade_url = `${this.data.url}/store/${response.bin_dir}/${image.name}`; + this.sha256_unsigned = image.sha256_unsigned; + let sysupgrade_url = `${data.url}/store/${response.bin_dir}/${image.name}`; let keep = E('input', { type: 'checkbox' }); keep.checked = true; @@ -123,7 +107,7 @@ return view.extend({ image.sha256, ]; - if (this.data.advanced_mode == 1) { + if (data.advanced_mode == 1) { fields.push( _('Profile'), response.id, @@ -142,7 +126,7 @@ return view.extend({ '', E('a', { href: sysupgrade_url }, _('Download firmware image')) ); - if (this.data.rebuilder) { + if (data.rebuilder) { fields.push(_('Rebuilds'), E('div', { id: 'rebuilder_status' })); } @@ -185,15 +169,15 @@ return view.extend({ ]; ui.showModal(_('Successfully created firmware image'), modal_body); - if (this.data.rebuilder) { - this.handleRebuilder(); + if (data.rebuilder) { + this.handleRebuilder(content, data, firmware); } } }, handle202: function (response) { response = response.json(); - this.data.request_hash = response.request_hash; + this.request_hash = response.request_hash; if ('queue_position' in response) { ui.showModal(_('Queued...'), [ @@ -219,8 +203,14 @@ return view.extend({ } }, - handleError: function (response) { + handleError: function (response, data, firmware) { response = response.json(); + const request_data = { + ...data, + request_hash: this.request_hash, + sha256_unsigned: this.sha256_unsigned, + ...firmware + }; let body = [ E('p', {}, _('Server response: %s').format(response.detail)), E( @@ -229,7 +219,7 @@ return view.extend({ _('Please report the error message and request') ), E('p', {}, _('Request Data:')), - E('pre', {}, JSON.stringify({ ...this.data, ...this.firmware }, null, 4)), + E('pre', {}, JSON.stringify({ ...request_data }, null, 4)), ]; if (response.stdout) { @@ -251,23 +241,23 @@ return view.extend({ ui.showModal(_('Error building the firmware image'), body); }, - handleRequest: function (server, main) { + handleRequest: function (server, main, content, data, firmware) { let request_url = `${server}/api/v1/build`; let method = 'POST'; - let content = this.firmware; + let local_content = content; /** * If `request_hash` is available use a GET request instead of * sending the entire object. */ - if (this.data.request_hash && main == true) { - request_url += `/${this.data.request_hash}`; - content = {}; + if (this.request_hash && main == true) { + request_url += `/${this.request_hash}`; + local_content = {}; method = 'GET'; } request - .request(request_url, { method: method, content: content }) + .request(request_url, { method: method, content: local_content }) .then((response) => { switch (response.status) { case 202: @@ -285,13 +275,13 @@ return view.extend({ case 200: if (main == true) { poll.remove(this.pollFn); - this.handle200(response); + this.handle200(response, content, data, firmware); } else { poll.remove(this.rebuilder_polls[server]); response = response.json(); let view = document.getElementById(server); - let image = this.selectImage(response.images); - if (image.sha256_unsigned == this.data.sha256_unsigned) { + let image = this.selectImage(response.images, data, firmware); + if (image.sha256_unsigned == this.sha256_unsigned) { view.innerText = '✅ %s'.format(server); } else { view.innerHTML = `⚠️ ${server} (