views and misc

This commit is contained in:
Flummi 2018-02-19 10:34:37 +01:00
parent 96ae3cac24
commit ddbb2ff746
5 changed files with 78 additions and 28 deletions

View File

@ -1,32 +1,48 @@
import express from "express";
const router = express.Router();
import highlight from "highlight.js";
import db from "../../lib/sql";
router.get("/", (req, res) => {
const query = "select p.uuid, p.stamp, p.title, p.paste, l.name as language, r.uuid as reply from `pastes` as p "
const queries = {
all: "select p.id, p.uuid, p.stamp, p.desc, p.paste, l.name as language, r.uuid as reply from `pastes` as p "
+ "left join `languages` as l on l.id = p.lang "
+ "left join `pastes` as r on r.id = p.reply "
+ "order by p.id desc "
+ "limit 5";
db.exec(query)
+ "order by p.id desc limit 5",
single: "select p.id, p.uuid, p.stamp, p.desc, p.paste, l.name as language, r.uuid as reply from `pastes` as p "
+ "left join `languages` as l on l.id = p.lang "
+ "left join `pastes` as r on r.id = p.reply "
+ "where p.uuid = ? limit 1"
};
export default express.Router()
.get("/", (req, res) => {
db.exec(queries.all)
.then(rows => {
const pastes = rows.map(r => {
res.render("view", { pastes: rows.map(r => {
const paste = new Buffer(r.paste, "base64").toString("ascii");
return {
title: r.title,
uuid: r.uuid,
paste: highlight.highlightAuto(r.paste).value,
paste: highlight.highlightAuto(paste).value,
language: r.language,
desc: r.reply ? `Reply to <a href="/${r.reply}/" class="descID">/${r.reply}/</a>` : "No description.",
rows: r.paste.split(/\r?\n/).length
rows: paste.split(/\r?\n/).length
};
});
res.render("view", { pastes: pastes });
})});
}).catch(err => res.render("view"));
})
.catch(err => {
res.render("view");
.get("/:uuid", (req, res) => {
if(req.params.uuid.length !== 8)
return res.send("error");
db.exec(queries.single, [req.params.uuid])
.then(rows => {
const r = rows[0];
const paste = new Buffer(r.paste, "base64").toString("ascii");
res.render("viewsingle", { paste: {
uuid: r.uuid,
paste: highlight.highlightAuto(paste).value,
language: r.lang,
desc: r.desc,
rows: paste.split(/\r?\n/).length
}});
}).catch(err => res.send("paste not found"));
});
});
export default router;

7
views/contact.handlebars Normal file
View File

@ -0,0 +1,7 @@
<h1><a name="contact">Contact</a></h1>
<p>You can contact me via:</p>
<ul>
<li>Email: <a href="mailto:mail@fpaste.cc">mail@fpaste.cc</a></li>
<li>Telegram: Flummsi</li>
<li>IRC: Flummi on <a href="https://n0xy.net">n0xy.net</a></li>
</ul>

View File

@ -20,9 +20,15 @@
<li><hr></li>
<li class="highlight"><a href="/u">Login</a></li>
<li><hr></li>
<li class="highlight"><a href="/a">About</a></li>
<li class="highlight"><a href="/a">About</a>
<ul class="submenu">
<li><a href="/a/howto">How to</a></li>
<li><a href="/a/contact">Contact</a></li>
<li><a href="/a/statistics">Statistics</a></li>
</ul>
</li>
</menu>
<section id="notifications"></section>
<section id="notifications">{{notification}}</section>
<section id="main">
{{{body}}}
</section>

View File

@ -0,0 +1,6 @@
<h1><a name="statistics">Statistics</a></h1>
<p>There are currently:</p>
<ul>
<li>{{pastes}} unique pastes</li>
<li>{{users}} active users</li>
</ul>

View File

@ -0,0 +1,15 @@
<div class="pasteInfo">
<p class="timestamp">15:13 - Thu 2017.06.15</p>
<p class="language"><a href="/v/lang/{{paste.language}}">{{paste.language}}</a></p>
<p>Paste: <a href="/{{paste.uuid}}/">/{{paste.uuid}}/</a><a href="/v/id/{{paste.uuid}}">Show related</a></p>
<p class="desc">{{{paste.desc}}}</p>
</div>
<div class="formatedCode">
<div class="lineNumbers">
<pre class="lineNumbers">{{#times paste.rows}}<a href="/{{../paste.uuid}}/#{{this}}" name="{{this}}">{{this}}</a>{{/times}}</pre>
</div>
<div class="sourceCode">
<pre>
{{{paste.paste}}}</pre>
</div>
</div>