discourse/app/assets/javascripts/admin/models/backup.js.es6

74 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error";
2019-11-09 03:13:35 +08:00
import EmberObject from "@ember/object";
2016-07-05 02:15:51 +08:00
2019-11-09 03:13:35 +08:00
const Backup = EmberObject.extend({
destroy() {
return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
},
restore() {
return ajax("/admin/backups/" + this.filename + "/restore", {
type: "POST",
data: { client_id: window.MessageBus.clientId }
});
}
});
Backup.reopenClass({
find() {
return ajax("/admin/backups.json")
.then(backups => backups.map(backup => Backup.create(backup)))
.catch(error => {
bootbox.alert(
I18n.t("admin.backups.backup_storage_error", {
error_message: extractError(error)
})
);
return [];
});
},
start(withUploads) {
2018-06-15 23:03:24 +08:00
if (withUploads === undefined) {
withUploads = true;
}
2016-07-01 01:55:44 +08:00
return ajax("/admin/backups", {
type: "POST",
data: {
with_uploads: withUploads,
client_id: window.MessageBus.clientId
}
}).then(result => {
2018-06-15 23:03:24 +08:00
if (!result.success) {
bootbox.alert(result.message);
}
});
},
cancel() {
return ajax("/admin/backups/cancel.json", {
2018-06-15 23:03:24 +08:00
type: "DELETE"
}).then(result => {
2018-06-15 23:03:24 +08:00
if (!result.success) {
bootbox.alert(result.message);
}
});
},
rollback() {
return ajax("/admin/backups/rollback.json", {
2018-06-15 23:03:24 +08:00
type: "POST"
}).then(result => {
if (!result.success) {
bootbox.alert(result.message);
} else {
// redirect to homepage (session might be lost)
window.location = Discourse.getURL("/");
}
});
}
});
export default Backup;