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