Skip to content

Commit

Permalink
Fix single event entry download
Browse files Browse the repository at this point in the history
For event entry download, the href not work since the event entry
download only work with header of "Accept: application/octet-stream" or
the default "*/*", change to click function to make it work.

Refer: https://gerrit.openbmc.org/c/openbmc/bmcweb/+/40136

Change-Id: I11051e913bfd71ef081bed93ffcbeeb1edd8c730
Signed-off-by: Sean Zhang <xiazhang@nvidia.com>
  • Loading branch information
seanzhangseu committed Jul 26, 2024
1 parent 1ff8e89 commit 582e954
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
"errorLogStatusUpdate": "Error updating log status.",
"errorResolveLogs": "Error resolving %{count} log. | Error resolving %{count} logs.",
"errorUnresolveLogs": "Error unresolving %{count} log. | Error unresolving %{count} logs.",
"errorDownloadEventEntry": "Error download event log entry.",
"successDelete": "Successfully deleted %{count} log. | Successfully deleted %{count} logs.",
"successResolveLogs": "Successfully resolved %{count} log. | Successfully resolved %{count} logs.",
"successUnresolveLogs": "Successfully unresolved %{count} log. | Successfully unresolved %{count} logs."
Expand Down
16 changes: 16 additions & 0 deletions src/store/modules/Logs/EventLogStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,22 @@ const EventLogStore = {
throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate'));
});
},
async downloadEntry(_, uri) {
return await api
.get(uri)
.then((response) => {
const blob = new Blob([response.data], {
type: response.headers['content-type'],
});
return blob;
})
.catch((error) => {
console.log(error);
throw new Error(
i18n.t('pageEventLogs.toast.errorDownloadEventEntry'),
);
});
},
},
};

Expand Down
20 changes: 15 additions & 5 deletions src/views/Logs/EventLogs/EventLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@
</dl>
</b-col>
<b-col class="text-nowrap">
<b-button
class="btn btn-secondary float-right"
:href="item.additionalDataUri"
target="_blank"
>
<b-button @click="downloadEntry(item.additionalDataUri)">
<icon-download />{{ $t('pageEventLogs.additionalDataUri') }}
</b-button>
</b-col>
Expand Down Expand Up @@ -471,6 +467,20 @@ export default {
});
},
methods: {
downloadEntry(uri) {
let filename = uri?.split('LogServices/')?.[1];
filename.replace(RegExp('/', 'g'), '_');
this.$store
.dispatch('eventLog/downloadEntry', uri)
.then((blob) => {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
URL.revokeObjectURL(link.href);
})
.catch(({ message }) => this.errorToast(message));
},
changelogStatus(row) {
this.$store
.dispatch('eventLog/updateEventLogStatus', {
Expand Down

0 comments on commit 582e954

Please sign in to comment.