forked from projects/fipamo
fixed git ignore remant blocking new api path
This commit is contained in:
parent
96e7fddcdf
commit
efb20eeeb3
2 changed files with 90 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,7 +2,6 @@ node_modules/
|
|||
.sass-cache/
|
||||
.cache/
|
||||
.nova/
|
||||
/*
|
||||
!public/
|
||||
public/*
|
||||
!public/favicon.ico
|
||||
|
|
90
brain/api/v1/backup.js
Normal file
90
brain/api/v1/backup.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||
import Auth from '../../data/Auth';
|
||||
import Utils from '../../data/Utils';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const multer = require('multer');
|
||||
const auth = new Auth();
|
||||
const utils = new Utils();
|
||||
|
||||
var backup_upload = multer().array('backup_upload');
|
||||
|
||||
/***
|
||||
CREATE BACK UP
|
||||
*/
|
||||
router.post('/create', (req, res) => {
|
||||
auth.authCheck(req)
|
||||
.then(() => {
|
||||
utils
|
||||
.createBackup()
|
||||
.then(() => {
|
||||
res.json({
|
||||
type: DataEvent.API_BACKUP_CREATE,
|
||||
message: "You're backed up. Hi fives"
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: err.message
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: err.message
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/***
|
||||
RETRIEVE BACKUP
|
||||
*/
|
||||
router.get('/download', (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);
|
||||
} else {
|
||||
res.json({
|
||||
type: DataEvent.REQUEST_LAME,
|
||||
message: "You're not logged in, champ"
|
||||
});
|
||||
}
|
||||
|
||||
//Move to route?
|
||||
});
|
||||
|
||||
/***
|
||||
RESTORE BACKUP
|
||||
*/
|
||||
|
||||
router.post('/restore', backup_upload, (req, res) => {
|
||||
auth.authCheck(req)
|
||||
.then(() => {
|
||||
utils
|
||||
.restoreBackup(req.files[0])
|
||||
.then(() => {
|
||||
res.json({
|
||||
type: DataEvent.API_BACKUP_RESTORE,
|
||||
message: 'Settings, files and pages restored. Nice work.'
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: 'Backup not restored. Uh oh.'
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: err.message
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Reference in a new issue