luci-app-attendedsysupgrade: apply changes to package list
authorEric Fahlgren <ericfahlgren@gmail.com>
Fri, 7 Feb 2025 21:02:24 +0000 (13:02 -0800)
committerPaul Spooren <mail@aparcar.org>
Sat, 8 Feb 2025 10:35:25 +0000 (10:35 +0000)
Utilize the 'package_changes' from the ASU server to update the package list
for the build request.

Links: https://github.com/openwrt/asu/commit/2bff208387d69a5a1723032a45e672650c17de62
Signed-off-by: Eric Fahlgren <ericfahlgren@gmail.com>
applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js

index 32698b3d028fa887a207c8c373ed8c47da99e5b8..03244a86525446f36fd1fc4dfef07e66f6887b9f 100644 (file)
@@ -78,6 +78,44 @@ return view.extend({
        request_hash: '',
        sha256_unsigned: '',
 
+       applyPackageChanges: async function(packages, data, firmware) {
+               const overview_url = `${data.url}/api/v1/overview`;
+               const revision_url = `${data.url}/api/v1/revision/${firmware.version}/${firmware.target}`;
+
+               let changes, target_revision;
+
+               await Promise.all([
+                       request.get(overview_url).then(
+                               (response) => {
+                                       let json = response.json();
+                                       changes = json.branches[get_branch(firmware.version)].package_changes;
+                               },
+                               (failed) => {
+                                       ui.addNotification(null, E('p', _(`Get overview failed ${failed}`)));
+                               }
+                       ),
+                       request.get(revision_url).then(
+                               (response) => {
+                                       target_revision = get_revision_count(response.json().revision);
+                               },
+                               (failed) => {
+                                       ui.addNotification(null, E('p', _(`Get revision failed ${failed}`)));
+                               }
+                       ),
+               ]);
+
+               for (const change of changes) {
+                       let idx = packages.indexOf(change.source);
+                       if (idx >= 0 && change.revision <= target_revision) {
+                               if (change.target)
+                                       packages[idx] = change.target;
+                               else
+                                       packages.splice(idx, 1);
+                       }
+               }
+               return packages;
+       },
+
        selectImage: function (images, data, firmware) {
                var filesystemFilter = function(e) {
                        return (e.filesystem == firmware.filesystem);
@@ -543,17 +581,19 @@ return view.extend({
                                                                        class: 'btn cbi-button cbi-button-positive important',
                                                                        click: ui.createHandlerFn(this, function () {
                                                                                map.save().then(() => {
-                                                                                       const content = {
-                                                                                               ...firmware,
-                                                                                               packages: mapdata.request.packages,
-                                                                                               version: mapdata.request.version,
-                                                                                               profile: mapdata.request.profile
-                                                                                       };
-                                                                                       this.pollFn = L.bind(function () {
-                                                                                               this.handleRequest(url, true, content, data, firmware);
-                                                                                       }, this);
-                                                                                       poll.add(this.pollFn, 5);
-                                                                                       poll.start();
+                                                                                       this.applyPackageChanges(mapdata.request.packages, data, firmware).then((packages) => {
+                                                                                               const content = {
+                                                                                                       ...firmware,
+                                                                                                       packages: packages,
+                                                                                                       version: mapdata.request.version,
+                                                                                                       profile: mapdata.request.profile
+                                                                                               };
+                                                                                               this.pollFn = L.bind(function () {
+                                                                                                       this.handleRequest(url, true, content, data, firmware);
+                                                                                               }, this);
+                                                                                               poll.add(this.pollFn, 5);
+                                                                                               poll.start();
+                                                                                       });
                                                                                });
                                                                        }),
                                                                },