From 2d96e55bc61d6a5ba3fd8799e56c219c4d9e28c7 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 24 Aug 2020 13:47:15 -0700 Subject: [PATCH] updated src files for backup patch --- src/com/events/DataEvent.js | 3 ++ src/libraries/FipamoAdminAPI.js | 60 ++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/com/events/DataEvent.js b/src/com/events/DataEvent.js index 77b1fc0..f053afb 100644 --- a/src/com/events/DataEvent.js +++ b/src/com/events/DataEvent.js @@ -27,6 +27,9 @@ export const API_PAGE_WRITE = 'writingItDown'; export const API_PAGE_CREATE = 'writingNewEntry'; export const API_PAGE_DELETE = 'erasingPage'; export const API_SETTINGS_WRITE = 'savingSettings'; +export const API_BACKUP_CREATE = 'createBackup'; +export const API_BACKUP_DOWNLOAD = 'downloadBackup'; +export const API_BACKUP_RESTORE = 'downloadBackup'; export const API_IMAGES_UPLOAD = 'uploadProfileImages'; export const API_RENDER_PAGES = 'renderPages'; export const API_INIT = 'blogInit'; diff --git a/src/libraries/FipamoAdminAPI.js b/src/libraries/FipamoAdminAPI.js index fedcfe4..7436dec 100644 --- a/src/libraries/FipamoAdminAPI.js +++ b/src/libraries/FipamoAdminAPI.js @@ -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);