2017-03-15 02:01:55 -06:00
|
|
|
'use strict';
|
|
|
|
|
2017-03-15 02:08:12 -06:00
|
|
|
const router = require('express').Router(),
|
2016-05-31 21:54:21 -06:00
|
|
|
mw = require('../middleware.js'),
|
2017-04-26 21:13:14 -06:00
|
|
|
env = require('../env/env.js'),
|
2017-04-01 11:03:05 -06:00
|
|
|
User = require('../models.js').user;
|
2017-05-08 18:12:58 -06:00
|
|
|
|
2017-04-01 11:03:05 -06:00
|
|
|
|
|
|
|
// Redirect to real slug
|
2017-04-13 16:53:18 -06:00
|
|
|
router.get('/', mw.ensureAuth, (req,res)=>{
|
2017-05-08 18:12:58 -06:00
|
|
|
if (req.query.new){
|
|
|
|
res.redirect(`/map/${req.user.slug}?new=1`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res.redirect(`/map/${req.user.slug}`);
|
|
|
|
}
|
2017-04-01 11:03:05 -06:00
|
|
|
});
|
2016-05-31 21:54:21 -06:00
|
|
|
|
|
|
|
// Show map
|
2017-04-13 16:53:18 -06:00
|
|
|
router.get('/:slug?', (req,res,next)=>{
|
2017-04-25 18:01:35 -06:00
|
|
|
|
2017-04-14 18:19:06 -06:00
|
|
|
User.findOne({slug:req.params.slug})
|
|
|
|
.then( (mapuser)=>{
|
2017-04-20 20:31:10 -06:00
|
|
|
if (!mapuser){ next(); } //404
|
|
|
|
else {
|
2017-05-23 11:44:16 -06:00
|
|
|
var active = '';
|
2017-05-23 11:04:01 -06:00
|
|
|
if (req.user && req.user.id===mapuser.id){ active='map'; }
|
2017-04-01 11:03:05 -06:00
|
|
|
res.render('map', {
|
2017-05-23 11:04:01 -06:00
|
|
|
active: active,
|
2016-05-31 21:54:21 -06:00
|
|
|
mapuser: mapuser,
|
2017-04-01 11:03:05 -06:00
|
|
|
mapApi: env.googleMapsAPI,
|
2017-04-14 18:19:06 -06:00
|
|
|
user: req.user,
|
2016-05-31 21:54:21 -06:00
|
|
|
noFooter: '1',
|
2017-04-14 18:19:06 -06:00
|
|
|
noHeader: (req.query.noheader)?req.query.noheader.match(/\d/)[0]:0,
|
2017-05-08 18:12:58 -06:00
|
|
|
disp: (req.query.disp)?req.query.disp.match(/\d/)[0]:2, // 0=map, 1=streetview, 2=both
|
|
|
|
newuserurl: (req.query.new)? env.url+'/map/'+req.params.slug : ''
|
2016-05-31 21:54:21 -06:00
|
|
|
});
|
|
|
|
}
|
2017-04-14 18:19:06 -06:00
|
|
|
}).catch( (err)=>{
|
|
|
|
mw.throwErr(err,req);
|
|
|
|
});
|
2016-05-31 21:54:21 -06:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-03-17 08:41:38 -06:00
|
|
|
module.exports = router;
|