|
|
|
@ -18,6 +18,10 @@ export const API_UPLOAD_AVATAR = '/api/v1/settings/add-avatar';
|
|
|
|
|
export const API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background';
|
|
|
|
|
export const API_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
|
|
|
|
|
export const API_NAV_SYNC = '/api/v1/settings/nav-sync';
|
|
|
|
|
export const API_CREATE_BACKUP = '/api/v1/backup/create';
|
|
|
|
|
export const API_DOWNLOAD_BACKUP = '/api/v1/backup/download';
|
|
|
|
|
export const API_RESTORE_BACKUP = '/api/v1/backup/restore';
|
|
|
|
|
export const API_INIT_RESTORE_BACKUP = '/api/v1/backup/init-restore';
|
|
|
|
|
export const API_SEND_MAIL = '/api/v1/mailer';
|
|
|
|
|
import * as DataEvent from '../com/events/DataEvent';
|
|
|
|
|
export default class APIUtils {
|
|
|
|
@ -188,6 +192,58 @@ export default class APIUtils {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
handleBackup(id, files) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var url, event, method, type, data;
|
|
|
|
|
|
|
|
|
|
if (id === 'create-backup') {
|
|
|
|
|
url = API_CREATE_BACKUP;
|
|
|
|
|
event = DataEvent.API_BACKUP_CREATE;
|
|
|
|
|
method = REQUEST_TYPE_POST;
|
|
|
|
|
type = CONTENT_TYPE_JSON;
|
|
|
|
|
data = { task: 'create_backup' };
|
|
|
|
|
} else {
|
|
|
|
|
url = API_RESTORE_BACKUP;
|
|
|
|
|
event = DataEvent.API_BACKUP_RESTORE;
|
|
|
|
|
method = REQUEST_TYPE_POST;
|
|
|
|
|
type = CONTENT_TYPE_FORM;
|
|
|
|
|
data = new FormData();
|
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
|
var file = files[i];
|
|
|
|
|
// Check the file type.
|
|
|
|
|
if (!file.type.match('application.zip')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
data.append('backup_upload', file, file.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._request(url, event, method, type, data)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
handleInitRestore(form) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
var url, event, method, type, data;
|
|
|
|
|
|
|
|
|
|
url = API_INIT_RESTORE_BACKUP;
|
|
|
|
|
event = DataEvent.API_BACKUP_RESTORE;
|
|
|
|
|
method = REQUEST_TYPE_POST;
|
|
|
|
|
type = CONTENT_TYPE_FORM;
|
|
|
|
|
data = new FormData(form);
|
|
|
|
|
this._request(url, event, method, type, data)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
|
// private
|
|
|
|
|
//--------------------------
|
|
|
|
@ -218,7 +274,9 @@ export default class APIUtils {
|
|
|
|
|
eventType === DataEvent.API_IMAGES_UPLOAD ||
|
|
|
|
|
eventType === DataEvent.API_SETTINGS_WRITE ||
|
|
|
|
|
eventType === DataEvent.API_PAGE_DELETE ||
|
|
|
|
|
eventType === DataEvent.API_RENDER_PAGES
|
|
|
|
|
eventType === DataEvent.API_RENDER_PAGES ||
|
|
|
|
|
eventType === DataEvent.API_BACKUP_CREATE ||
|
|
|
|
|
eventType === DataEvent.API_BACKUP_RESTORE
|
|
|
|
|
)
|
|
|
|
|
request.setRequestHeader('x-access-token', self.token);
|
|
|
|
|
|
|
|
|
|