views and misc
This commit is contained in:
parent
96ae3cac24
commit
ddbb2ff746
|
@ -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 "
|
||||
+ "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)
|
||||
.then(rows => {
|
||||
const pastes = rows.map(r => {
|
||||
return {
|
||||
title: r.title,
|
||||
uuid: r.uuid,
|
||||
paste: highlight.highlightAuto(r.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
|
||||
};
|
||||
});
|
||||
res.render("view", { pastes: pastes });
|
||||
})
|
||||
.catch(err => {
|
||||
res.render("view");
|
||||
});
|
||||
});
|
||||
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",
|
||||
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 router;
|
||||
export default express.Router()
|
||||
.get("/", (req, res) => {
|
||||
db.exec(queries.all)
|
||||
.then(rows => {
|
||||
res.render("view", { pastes: rows.map(r => {
|
||||
const paste = new Buffer(r.paste, "base64").toString("ascii");
|
||||
return {
|
||||
uuid: r.uuid,
|
||||
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: paste.split(/\r?\n/).length
|
||||
};
|
||||
})});
|
||||
}).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"));
|
||||
});
|
7
views/contact.handlebars
Normal file
7
views/contact.handlebars
Normal 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>
|
|
@ -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>
|
||||
|
|
6
views/statistics.handlebars
Normal file
6
views/statistics.handlebars
Normal 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>
|
15
views/viewsingle.handlebars
Normal file
15
views/viewsingle.handlebars
Normal 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>
|
Loading…
Reference in New Issue
Block a user