feat(xo-web/downloadLog): use .json extension for JSON values

This commit is contained in:
Julien Fontanet
2022-11-20 23:20:01 +01:00
parent 4101bf3ba5
commit 5ad94504e3
3 changed files with 7 additions and 5 deletions

View File

@@ -591,9 +591,11 @@ export const safeDateFormat = ms => new Date(ms).toISOString().replace(/:/g, '_'
// ===================================================================
export const downloadLog = ({ log, date, type }) => {
const isJson = typeof log !== 'string'
const anchor = document.createElement('a')
anchor.href = window.URL.createObjectURL(createBlobFromString(log))
anchor.download = `${safeDateFormat(date)} - ${type}.log`
anchor.href = window.URL.createObjectURL(createBlobFromString(isJson ? JSON.stringify(log, null, 2) : log))
anchor.download = `${safeDateFormat(date)} - ${type}.${isJson ? 'json' : 'log'}`
anchor.style.display = 'none'
document.body.appendChild(anchor)
anchor.click()

View File

@@ -29,8 +29,8 @@ export default decorate([
effects: {
_downloadLog:
() =>
({ formattedLog }, { log }) =>
downloadLog({ log: formattedLog, date: log.start, type: 'backup NG' }),
(_, { log }) =>
downloadLog({ log, date: log.start, type: 'backup NG' }),
restartFailedVms:
(_, params) =>
async (_, { log: { jobId: id, scheduleId: schedule, tasks, infos } }) => {

View File

@@ -94,7 +94,7 @@ const INDIVIDUAL_ACTIONS = [
label: _('logDownload'),
handler: task =>
downloadLog({
log: JSON.stringify(task, null, 2),
log: task,
date: task.start,
type: 'Metadata restore',
}),