|
126 | 126 | {{ 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!') }}
|
127 | 127 | <button
|
128 | 128 | :disabled="loadingExportSettings"
|
| 129 | + class="backup-settings__actions__action__export" |
129 | 130 | :class="{loading: loadingExportSettings}"
|
130 | 131 | @click="downloadSettings">
|
131 | 132 | <span class="icon icon-external" />
|
132 | 133 | {{ t('backup', 'Export configuration') }}
|
133 | 134 | </button>
|
134 | 135 | </div>
|
135 |
| - <div v-if="exportPrivateKey !== undefined" class="backup-settings__export__info"> |
| 136 | + <div v-if="exportedPrivateKey !== undefined" class="backup-settings__export__info"> |
136 | 137 | {{ 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:') }}
|
137 | 138 | <br>
|
138 |
| - <code><b>{{ exportPrivateKey }}</b></code> |
| 139 | + <code><b>{{ exportedPrivateKey }}</b></code> |
139 | 140 | <br>
|
140 | 141 | </div>
|
141 | 142 |
|
@@ -219,7 +220,8 @@ export default {
|
219 | 220 | partial: 0,
|
220 | 221 | full: 0,
|
221 | 222 | }),
|
222 |
| - exportPrivateKey: undefined, |
| 223 | + exportedPrivateKey: undefined, |
| 224 | + exportedSettings: undefined, |
223 | 225 | loadingFetchSettings: false,
|
224 | 226 | loadingSetSettings: 0,
|
225 | 227 | loadingRequestRestoringPoint: false,
|
@@ -306,31 +308,40 @@ export default {
|
306 | 308 | return
|
307 | 309 | }
|
308 | 310 |
|
| 311 | + if (this.exportedSettings !== undefined) { |
| 312 | + this.saveFile('settings.asc', this.exportedSettings) |
| 313 | + return |
| 314 | + } |
| 315 | +
|
309 | 316 | try {
|
310 | 317 | this.loadingExportSettings = true
|
311 | 318 | 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) |
312 | 322 |
|
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) |
327 | 323 | } catch (error) {
|
328 | 324 | showError(t('backup', 'Unable to export settings'))
|
329 | 325 | logger.error('An error occurred while exporting the settings', { error })
|
330 | 326 | } finally {
|
331 | 327 | this.loadingExportSettings = false
|
332 | 328 | }
|
333 | 329 | },
|
| 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 | + }, |
334 | 345 | },
|
335 | 346 | }
|
336 | 347 | </script>
|
@@ -386,6 +397,11 @@ button.loading {
|
386 | 397 | margin-bottom: 12px;
|
387 | 398 | color: var(--color-error);
|
388 | 399 | }
|
| 400 | +
|
| 401 | + &__export { |
| 402 | + display: block; |
| 403 | + margin-top: 16px; |
| 404 | + } |
389 | 405 | }
|
390 | 406 | }
|
391 | 407 |
|
|
0 commit comments