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