Skip to content

Commit cf1f694

Browse files
committed
Prevent double click on export button
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 3033160 commit cf1f694

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/components/GeneralSettingsSection.vue

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,17 @@
126126
{{ t('backup', 'You can export your settings with the below button. The exported file is important as it allows you to restore your backup in case of full data lost. Keep it in a safe place!') }}
127127
<button
128128
:disabled="loadingExportSettings"
129+
class="backup-settings__actions__action__export"
129130
:class="{loading: loadingExportSettings}"
130131
@click="downloadSettings">
131132
<span class="icon icon-external" />
132133
{{ t('backup', 'Export configuration') }}
133134
</button>
134135
</div>
135-
<div v-if="exportPrivateKey !== undefined" class="backup-settings__export__info">
136+
<div v-if="exportedPrivateKey !== undefined" class="backup-settings__export__info">
136137
{{ t('backup', 'Your settings export as been downloaded encrypted. To be able to decrypt it later, please keep the following private key in a safe place:') }}
137138
<br>
138-
<code><b>{{ exportPrivateKey }}</b></code>
139+
<code><b>{{ exportedPrivateKey }}</b></code>
139140
<br>
140141
</div>
141142

@@ -219,7 +220,8 @@ export default {
219220
partial: 0,
220221
full: 0,
221222
}),
222-
exportPrivateKey: undefined,
223+
exportedPrivateKey: undefined,
224+
exportedSettings: undefined,
223225
loadingFetchSettings: false,
224226
loadingSetSettings: 0,
225227
loadingRequestRestoringPoint: false,
@@ -306,31 +308,40 @@ export default {
306308
return
307309
}
308310
311+
if (this.exportedSettings !== undefined) {
312+
this.saveFile('settings.asc', this.exportedSettings)
313+
return
314+
}
315+
309316
try {
310317
this.loadingExportSettings = true
311318
const response = await axios.get(generateOcsUrl('apps/backup/setup/encrypted'))
319+
this.exportedSettings = response.data.ocs.data.content
320+
this.exportedPrivateKey = response.data.ocs.data.key
321+
this.saveFile('settings.asc', response.data.ocs.data.content)
312322
313-
this.exportPrivateKey = response.data.ocs.data.key
314-
315-
// From: https://stackoverflow.com/questions/13405129/javascript-create-and-save-file
316-
const file = new Blob([response.data.ocs.data.content], { type: 'asc' })
317-
const a = document.createElement('a')
318-
const url = URL.createObjectURL(file)
319-
a.href = url
320-
a.download = 'settings.asc'
321-
document.body.appendChild(a)
322-
a.click()
323-
setTimeout(() => {
324-
document.body.removeChild(a)
325-
window.URL.revokeObjectURL(url)
326-
}, 0)
327323
} catch (error) {
328324
showError(t('backup', 'Unable to export settings'))
329325
logger.error('An error occurred while exporting the settings', { error })
330326
} finally {
331327
this.loadingExportSettings = false
332328
}
333329
},
330+
331+
saveFile(name, content) {
332+
// From: https://stackoverflow.com/questions/13405129/javascript-create-and-save-file
333+
const file = new Blob([content], { type: 'asc' })
334+
const a = document.createElement('a')
335+
const url = URL.createObjectURL(file)
336+
a.href = url
337+
a.download = name
338+
document.body.appendChild(a)
339+
a.click()
340+
setTimeout(() => {
341+
document.body.removeChild(a)
342+
window.URL.revokeObjectURL(url)
343+
}, 0)
344+
},
334345
},
335346
}
336347
</script>
@@ -386,6 +397,11 @@ button.loading {
386397
margin-bottom: 12px;
387398
color: var(--color-error);
388399
}
400+
401+
&__export {
402+
display: block;
403+
margin-top: 16px;
404+
}
389405
}
390406
}
391407

0 commit comments

Comments
 (0)