1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-07 14:35:26 +02:00

Added checking favicon before uploading function, removed passing locals to views

This commit is contained in:
slaveeks 2022-07-07 11:08:35 +03:00
parent 2712378370
commit f1fa35564c
7 changed files with 20 additions and 21 deletions

View file

@ -24,15 +24,20 @@ app.set('views', path.join(__dirname, './', 'views'));
app.set('view engine', 'twig'); app.set('view engine', 'twig');
require('./utils/twig'); require('./utils/twig');
// Upload favicon by url, it's path on server is '/temp/favicon.{format}' // Check if favicon is not empty
downloadFavicon(favicon).then((res) => { if (favicon) {
app.locals.favicon = res; // Upload favicon by url, it's path on server is '/temp/favicon.{format}'
console.log('Favicon successfully uploaded'); downloadFavicon(favicon).then((res) => {
}) app.locals.favicon = res;
.catch( (err) => { console.log('Favicon successfully uploaded');
console.log(err); })
console.log('Favicon has not uploaded'); .catch( (err) => {
}); console.log(err);
console.log('Favicon has not uploaded');
});
} else {
console.log('Favicon is empty');
}
app.use(morgan('dev')); app.use(morgan('dev'));
app.use(express.json()); app.use(express.json());

View file

@ -36,7 +36,6 @@ router.get('*', verifyToken, async (req: Request, res: Response) => {
page, page,
pageParent, pageParent,
config: req.app.locals.config, config: req.app.locals.config,
favicon: req.app.locals.favicon,
}); });
} }
} }

View file

@ -28,7 +28,6 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Password not set', header: 'Password not set',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: req.app.locals.favicon,
}); });
return; return;
@ -39,7 +38,6 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Wrong password', header: 'Wrong password',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: req.app.locals.favicon,
}); });
return; return;
@ -62,7 +60,6 @@ router.post('/auth', parseForm, csrfProtection, async (req: Request, res: Respon
title: 'Login page', title: 'Login page',
header: 'Password not set', header: 'Password not set',
csrfToken: req.csrfToken(), csrfToken: req.csrfToken(),
favicon: req.app.locals.favicon
}); });
return; return;

View file

@ -10,8 +10,7 @@ router.get('/', verifyToken, async (req: Request, res: Response) => {
if (config.startPage) { if (config.startPage) {
return res.redirect(config.startPage); return res.redirect(config.startPage);
} }
res.render('pages/index', { isAuthorized: res.locals.isAuthorized, res.render('pages/index', { isAuthorized: res.locals.isAuthorized });
favicon: req.app.locals.favicon });
}); });
export default router; export default router;

View file

@ -45,7 +45,6 @@ router.get('/page/edit/:id', verifyToken, allowEdit, async (req: Request, res: R
page, page,
parentsChildrenOrdered, parentsChildrenOrdered,
pagesAvailable, pagesAvailable,
favicon: req.app.locals.favicon,
}); });
} catch (error) { } catch (error) {
res.status(404); res.status(404);
@ -67,8 +66,6 @@ router.get('/page/:id', verifyToken, async (req: Request, res: Response, next: N
res.render('pages/page', { res.render('pages/page', {
page, page,
pageParent, pageParent,
config: req.app.locals.config,
favicon: req.app.locals.favicon,
}); });
} catch (error) { } catch (error) {
res.status(404); res.status(404);

View file

@ -17,11 +17,11 @@
<body> <body>
{% include "components/header.twig" with res.locals.isAuthorized %} {% include "components/header.twig" with res.locals.isAuthorized %}
<div class="docs"> <div class="docs">
{% include "components/sidebar.twig" %} {% include "components/sidebar.twig" %}
<div class="docs__content"> <div class="docs__content">
<div class="docs__content-inner"> <div class="docs__content-inner">
{% block body %}{% endblock %} {% block body %}{% endblock %}
</div> </div>

View file

@ -10,6 +10,8 @@
<meta property="og:site_name" content="{{ config.title }}" /> <meta property="og:site_name" content="{{ config.title }}" />
<meta name="description" property="og:description" content="{{ config.description }}"> <meta name="description" property="og:description" content="{{ config.description }}">
</head> </head>
<script>
</script>
<body class="landing-body"> <body class="landing-body">
{% include "components/header.twig" %} {% include "components/header.twig" %}
<div class="landing-loader" id="frame-loader"> <div class="landing-loader" id="frame-loader">