forked from projects/fipamo
cleaned up backups on front end and backend
This commit is contained in:
parent
682bc32a46
commit
1fa21322fb
6 changed files with 42 additions and 31 deletions
|
@ -5,7 +5,6 @@ import Settings, { SETTINGS_FILE, SETTINGS_FOLKS } from '../../data/Settings';
|
|||
import Navigation from '../../data/Navigation';
|
||||
import Book from '../../data/Book';
|
||||
import Utils from '../../data/Utils';
|
||||
import { util } from 'prettier';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const multer = require('multer');
|
||||
|
@ -54,6 +53,7 @@ router.post('/sync', (req, res) => {
|
|||
.catch(err => {
|
||||
res.json({
|
||||
type: DataEvent.REQUEST_LAME,
|
||||
error: err.message,
|
||||
message: "Uh oh. Settings didn't take, sport"
|
||||
});
|
||||
});
|
||||
|
@ -238,23 +238,19 @@ router.post('/create-backup', (req, res) => {
|
|||
});
|
||||
|
||||
router.get('/download-backup', (req, res) => {
|
||||
if (req.session.user) {
|
||||
var filePath = 'content/backup.zip'; // Or format the path using the `id` rest param
|
||||
var fileName = 'backup.zip'; // The default name the browser will use
|
||||
|
||||
res.download(filePath, fileName);
|
||||
//Make secure
|
||||
/*
|
||||
auth.authCheck(req)
|
||||
.then(() => {
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
} else {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: err.message
|
||||
type: DataEvent.REQUEST_LAME,
|
||||
message: "You're not logged in, champ"
|
||||
});
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
//Move to route?
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -41,19 +41,19 @@ block main-content
|
|||
=settings.global.descriptions
|
||||
#member-utils.columns
|
||||
#util-1.column
|
||||
label MEMBER UTILS
|
||||
label BACKUP TOOLS
|
||||
br
|
||||
button#create-backup CREATE BACKUP
|
||||
br
|
||||
-if(settings.global.last_backup != null)
|
||||
br
|
||||
| The last back up was
|
||||
.backup-meta
|
||||
| The last back up was created
|
||||
a(href='/api/v1/settings/download-backup')= last_backup
|
||||
-else
|
||||
br
|
||||
span No back ups. Frowny face.
|
||||
#util-2.column
|
||||
<a href="">SOMETHING</a>
|
||||
label MAINTENANCE
|
||||
#option-settings.columns
|
||||
#theme-settings.column
|
||||
label THEMES
|
||||
|
|
|
@ -81,6 +81,7 @@ export default class SettingsIndex {
|
|||
document
|
||||
.getElementById('create-backup')
|
||||
.addEventListener('click', e => this.handleBackup(e));
|
||||
document.getElementById('get-backup').addEventListener('click', e => this.handleBackup(e));
|
||||
}
|
||||
//--------------------------
|
||||
// event handlers
|
||||
|
@ -176,9 +177,12 @@ export default class SettingsIndex {
|
|||
handleBackup(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let task = { task: 'create_backup' };
|
||||
let task;
|
||||
e.target.id === 'create-backup'
|
||||
? (task = { task: 'create_backup' })
|
||||
: (task = { task: 'get_backup' });
|
||||
admin
|
||||
.createBackup(task)
|
||||
.handleBackup(task)
|
||||
.then(r => {
|
||||
notify.alert(r.message, true);
|
||||
})
|
||||
|
|
|
@ -28,6 +28,7 @@ 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_IMAGES_UPLOAD = 'uploadProfileImages';
|
||||
export const API_RENDER_PAGES = 'renderPages';
|
||||
export const API_INIT = 'blogInit';
|
||||
|
|
|
@ -190,15 +190,19 @@ export default class APIUtils {
|
|||
});
|
||||
});
|
||||
}
|
||||
createBackup(data) {
|
||||
handleBackup(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._request(
|
||||
API_CREATE_BACKUP,
|
||||
DataEvent.API_BACKUP_CREATE,
|
||||
REQUEST_TYPE_POST,
|
||||
CONTENT_TYPE_JSON,
|
||||
data
|
||||
)
|
||||
var url, event, method;
|
||||
if (data.task === 'create_backup') {
|
||||
url = API_CREATE_BACKUP;
|
||||
event = DataEvent.API_BACKUP_CREATE;
|
||||
method = REQUEST_TYPE_POST;
|
||||
} else {
|
||||
url = API_DOWNLOAD_BACKUP;
|
||||
event = DataEvent.API_BACKUP_DOWNLOAD;
|
||||
method = REQUEST_TYPE_GET;
|
||||
}
|
||||
this._request(url, event, method, CONTENT_TYPE_JSON, data)
|
||||
.then(result => {
|
||||
resolve(result);
|
||||
})
|
||||
|
|
|
@ -74,6 +74,12 @@
|
|||
margin 0 5px 10px 0
|
||||
height 30px
|
||||
padding 10px
|
||||
.backup-meta
|
||||
background $primary - 60%
|
||||
color $white
|
||||
padding 8px
|
||||
border-radius 3px
|
||||
margin 5px 0 0 0
|
||||
|
||||
width 100%
|
||||
margin 20px auto
|
||||
|
|
Loading…
Reference in a new issue