|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
|
|
|
|
import Auth from '../../data/Auth';
|
|
|
|
|
import Render from '../../data/Render';
|
|
|
|
|
import SettingsData from '../../data/Settings';
|
|
|
|
|
import Book from '../../data/Book';
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
@ -13,6 +14,7 @@ const folks = require('../../../site/folks.json');
|
|
|
|
|
const auth = new Auth();
|
|
|
|
|
const render = new Render();
|
|
|
|
|
const book = new Book();
|
|
|
|
|
const settingsData = new SettingsData();
|
|
|
|
|
const uploadPath =
|
|
|
|
|
'./public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM');
|
|
|
|
|
fs.ensureDir(uploadPath, () => {
|
|
|
|
@ -35,48 +37,10 @@ var background_upload = multer({
|
|
|
|
|
}).array('background_upload');
|
|
|
|
|
//** SYNC POSTS */
|
|
|
|
|
router.post('/sync', (req, res) => {
|
|
|
|
|
let payload = req.body;
|
|
|
|
|
if (req.session.user) {
|
|
|
|
|
let user = req.session.user;
|
|
|
|
|
let found = _.find(folks, { id: user.id });
|
|
|
|
|
let needToUpdate = false;
|
|
|
|
|
if (found) {
|
|
|
|
|
let index = found.id - 1;
|
|
|
|
|
if (
|
|
|
|
|
folks[index].handle != payload.member.handle ||
|
|
|
|
|
folks[index].email != payload.member.email
|
|
|
|
|
) {
|
|
|
|
|
folks[index].handle = payload.member.handle;
|
|
|
|
|
folks[index].email = payload.member.email;
|
|
|
|
|
fs.writeJson('site/folks.json', folks);
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: "You're not logged in, champ"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_.isEqual(settings.global, payload.global)) {
|
|
|
|
|
let bg = payload.global.background;
|
|
|
|
|
payload.global.background = bg.substr(21, bg.length);
|
|
|
|
|
settings.global = payload.global;
|
|
|
|
|
needToUpdate = true;
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_.isEqual(settings.email, payload.email)) {
|
|
|
|
|
settings.email = payload.email;
|
|
|
|
|
needToUpdate = true;
|
|
|
|
|
} else {
|
|
|
|
|
//no need to save
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needToUpdate) {
|
|
|
|
|
fs.writeJson('site/settings.json', settings)
|
|
|
|
|
auth.authCheck(req)
|
|
|
|
|
.then(() => {
|
|
|
|
|
settingsData
|
|
|
|
|
.sync(req, res)
|
|
|
|
|
.then(() => {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.SETTINGS_UPDATED,
|
|
|
|
@ -84,12 +48,18 @@ router.post('/sync', (req, res) => {
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
//console.error(err);
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: "You're not logged in, champ"
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
//no need to update
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
res.json({
|
|
|
|
|
type: err.type,
|
|
|
|
|
message: err.message
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.post('/nav-sync', (req, res) => {
|
|
|
|
|