From efb20eeeb3ba92d7ef5229f9fc1321b1696d1612 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 17 Aug 2020 15:12:34 -0700 Subject: [PATCH] fixed git ignore remant blocking new api path --- .gitignore | 1 - brain/api/v1/backup.js | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 brain/api/v1/backup.js diff --git a/.gitignore b/.gitignore index 3abe600..1ef94b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ node_modules/ .sass-cache/ .cache/ .nova/ -/* !public/ public/* !public/favicon.ico diff --git a/brain/api/v1/backup.js b/brain/api/v1/backup.js new file mode 100644 index 0000000..b3d857c --- /dev/null +++ b/brain/api/v1/backup.js @@ -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;