2016-06-23 22:29:55 +00:00
|
|
|
import { Router } from 'express';
|
2016-11-17 16:15:35 +00:00
|
|
|
import { renderIndex } from '../views/index';
|
2017-01-06 20:05:02 +00:00
|
|
|
import { get404Sketch } from '../views/404Page';
|
2017-02-22 19:29:35 +00:00
|
|
|
import { userExists } from '../controllers/user.controller';
|
2018-02-19 20:21:47 +00:00
|
|
|
import { projectExists, projectForUserExists } from '../controllers/project.controller';
|
2019-07-09 08:35:24 +00:00
|
|
|
import { collectionForUserExists } from '../controllers/collection.controller';
|
2017-02-22 19:29:35 +00:00
|
|
|
|
|
|
|
const router = new Router();
|
2016-06-18 22:33:49 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
// this is intended to be a temporary file
|
2016-06-18 22:33:49 +00:00
|
|
|
// until i figure out isomorphic rendering
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/', (req, res) => {
|
2016-11-08 23:11:12 +00:00
|
|
|
res.send(renderIndex());
|
2016-06-18 22:33:49 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/signup', (req, res) => {
|
2017-09-29 18:52:20 +00:00
|
|
|
if (req.user) {
|
|
|
|
return res.redirect('/');
|
|
|
|
}
|
2017-10-16 03:27:05 +00:00
|
|
|
return res.send(renderIndex());
|
2016-06-18 22:33:49 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/projects/:project_id', (req, res) => {
|
2018-02-19 20:21:47 +00:00
|
|
|
projectExists(req.params.project_id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
2016-06-18 22:33:49 +00:00
|
|
|
});
|
|
|
|
|
2019-09-09 16:52:54 +00:00
|
|
|
router.get('/:username/sketches/:project_id/add-to-collection', (req, res) => {
|
|
|
|
projectForUserExists(req.params.username, req.params.project_id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/:username/sketches/:project_id', (req, res) => {
|
2018-02-19 20:21:47 +00:00
|
|
|
projectForUserExists(req.params.username, req.params.project_id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
2016-12-01 22:12:34 +00:00
|
|
|
});
|
|
|
|
|
2019-09-09 16:52:54 +00:00
|
|
|
router.get('/:username/sketches', (req, res) => {
|
|
|
|
userExists(req.params.username, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2018-10-18 18:10:37 +00:00
|
|
|
router.get('/:username/full/:project_id', (req, res) => {
|
|
|
|
projectForUserExists(req.params.username, req.params.project_id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
2017-06-01 04:08:11 +00:00
|
|
|
|
2018-10-18 18:10:37 +00:00
|
|
|
router.get('/full/:project_id', (req, res) => {
|
|
|
|
projectExists(req.params.project_id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
2016-08-17 22:13:17 +00:00
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/login', (req, res) => {
|
2017-09-29 18:52:20 +00:00
|
|
|
if (req.user) {
|
|
|
|
return res.redirect('/');
|
|
|
|
}
|
2017-10-16 03:27:05 +00:00
|
|
|
return res.send(renderIndex());
|
2016-06-18 22:33:49 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/reset-password', (req, res) => {
|
2016-11-08 23:11:12 +00:00
|
|
|
res.send(renderIndex());
|
2016-10-12 16:02:46 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/reset-password/:reset_password_token', (req, res) => {
|
2016-11-08 23:11:12 +00:00
|
|
|
res.send(renderIndex());
|
2016-10-18 20:07:25 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/verify', (req, res) => {
|
2017-06-26 16:48:28 +00:00
|
|
|
res.send(renderIndex());
|
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/sketches', (req, res) => {
|
2018-05-30 21:23:11 +00:00
|
|
|
if (req.user) {
|
|
|
|
res.send(renderIndex());
|
|
|
|
} else {
|
|
|
|
res.redirect('/login');
|
|
|
|
}
|
2018-05-30 04:37:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/assets', (req, res) => {
|
2018-05-30 21:23:11 +00:00
|
|
|
if (req.user) {
|
|
|
|
res.send(renderIndex());
|
|
|
|
} else {
|
|
|
|
res.redirect('/login');
|
|
|
|
}
|
2018-05-30 04:37:10 +00:00
|
|
|
});
|
|
|
|
|
2019-08-24 10:38:42 +00:00
|
|
|
router.get('/:username/assets', (req, res) => {
|
|
|
|
userExists(req.params.username, (exists) => {
|
|
|
|
const isLoggedInUser = req.user && req.user.username === req.params.username;
|
|
|
|
const canAccess = exists && isLoggedInUser;
|
|
|
|
return canAccess ?
|
|
|
|
res.send(renderIndex()) :
|
|
|
|
get404Sketch(html => res.send(html));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-30 04:37:10 +00:00
|
|
|
router.get('/account', (req, res) => {
|
2018-05-30 21:23:11 +00:00
|
|
|
if (req.user) {
|
|
|
|
res.send(renderIndex());
|
|
|
|
} else {
|
|
|
|
res.redirect('/login');
|
|
|
|
}
|
2016-07-05 20:04:14 +00:00
|
|
|
});
|
|
|
|
|
2018-01-09 20:57:49 +00:00
|
|
|
router.get('/about', (req, res) => {
|
2016-11-08 23:11:12 +00:00
|
|
|
res.send(renderIndex());
|
2016-08-22 16:35:59 +00:00
|
|
|
});
|
|
|
|
|
2020-06-12 19:09:30 +00:00
|
|
|
if (process.env.MOBILE_ENABLED) {
|
|
|
|
router.get('/mobile', (req, res) => {
|
2020-06-18 18:39:55 +00:00
|
|
|
res.send(renderIndex());
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/mobile/preview', (req, res) => {
|
|
|
|
res.send(renderIndex());
|
|
|
|
});
|
|
|
|
|
2020-06-23 18:54:09 +00:00
|
|
|
router.get('/mobile/preferences', (req, res) => {
|
2020-06-12 19:09:30 +00:00
|
|
|
res.send(renderIndex());
|
|
|
|
});
|
|
|
|
}
|
2018-02-09 21:32:06 +00:00
|
|
|
|
2019-09-08 16:54:49 +00:00
|
|
|
router.get('/:username/collections/create', (req, res) => {
|
|
|
|
userExists(req.params.username, (exists) => {
|
|
|
|
const isLoggedInUser = req.user && req.user.username === req.params.username;
|
|
|
|
const canAccess = exists && isLoggedInUser;
|
|
|
|
return canAccess ?
|
|
|
|
res.send(renderIndex()) :
|
|
|
|
get404Sketch(html => res.send(html));
|
|
|
|
});
|
2019-07-09 08:35:24 +00:00
|
|
|
});
|
|
|
|
|
2019-07-09 16:24:09 +00:00
|
|
|
router.get('/:username/collections/create', (req, res) => {
|
|
|
|
userExists(req.params.username, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2019-07-09 08:35:24 +00:00
|
|
|
router.get('/:username/collections/:id', (req, res) => {
|
|
|
|
collectionForUserExists(req.params.username, req.params.id, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2019-09-08 16:54:49 +00:00
|
|
|
router.get('/:username/collections', (req, res) => {
|
|
|
|
userExists(req.params.username, exists => (
|
|
|
|
exists ? res.send(renderIndex()) : get404Sketch(html => res.send(html))
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
export default router;
|