2019-10-14 18:23:29 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { task } from 'ember-concurrency';
|
|
|
|
import { getOwner } from '@ember/application';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { AbortController } from 'fetch';
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
file: null,
|
|
|
|
errors: null,
|
|
|
|
forceRestore: false,
|
|
|
|
flashMessages: service(),
|
|
|
|
isUploading: alias('restore.isRunning'),
|
|
|
|
abortController: null,
|
2021-12-17 03:44:29 +00:00
|
|
|
restore: task(function* () {
|
2019-10-14 18:23:29 +00:00
|
|
|
this.set('errors', null);
|
2022-11-09 23:15:31 +00:00
|
|
|
const adapter = getOwner(this).lookup('adapter:application');
|
2019-10-14 18:23:29 +00:00
|
|
|
try {
|
|
|
|
let url = '/v1/sys/storage/raft/snapshot';
|
|
|
|
if (this.forceRestore) {
|
|
|
|
url = `${url}-force`;
|
|
|
|
}
|
2022-11-09 23:15:31 +00:00
|
|
|
const file = new Blob([this.file], { type: 'application/gzip' });
|
|
|
|
const controller = new AbortController();
|
2019-10-14 18:23:29 +00:00
|
|
|
this.set('abortController', controller);
|
|
|
|
yield adapter.rawRequest(url, 'POST', { body: file, signal: controller.signal });
|
|
|
|
this.flashMessages.success('The snapshot was successfully uploaded!');
|
|
|
|
} catch (e) {
|
|
|
|
if (e.name === 'AbortError') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let resp;
|
|
|
|
if (e.json) {
|
|
|
|
resp = yield e.json();
|
|
|
|
}
|
2022-11-09 23:15:31 +00:00
|
|
|
const err = resp ? resp.errors : [e];
|
2019-10-14 18:23:29 +00:00
|
|
|
this.set('errors', err);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
actions: {
|
|
|
|
cancelUpload() {
|
|
|
|
this.abortController.abort();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|