diff --git a/src/fpaste.mjs b/src/fpaste.mjs index 8fe8a90..174312c 100644 --- a/src/fpaste.mjs +++ b/src/fpaste.mjs @@ -24,6 +24,7 @@ app .use("/", router.index) .use("/v", router.view) .use("/a", router.about) + .use("/test", router.newpaste) .get("/:uuid", (req, res) => { res.send(req.params.uuid); diff --git a/src/lib/index.mjs b/src/lib/index.mjs new file mode 100644 index 0000000..ccdc10a --- /dev/null +++ b/src/lib/index.mjs @@ -0,0 +1,27 @@ +import db from "./sql"; + +export const getPaste = id => new Promise((resolve, reject) => { + if(id | 0) { + const query = "select p.uuid, p.stamp, p.title, p.paste, l.name as lang, 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.id = ?"; + db.exec(query, [id]) + .then(row => { + resolve({ + uuid: row[0].uuid, + stamp: row[0].stamp, + title: row[0].title, + paste: row[0].paste, + lang: row[0].lang, + reply: row[0].reply + }); + }) + .catch(err => { + reject(err); + }); + } + else { + reject("NaN"); + } +}); \ No newline at end of file diff --git a/src/routes/index.mjs b/src/routes/index.mjs index d2e8e55..a34981f 100644 --- a/src/routes/index.mjs +++ b/src/routes/index.mjs @@ -1,10 +1,12 @@ import index from "./r/index"; import view from "./r/view"; import about from "./r/about"; +import newpaste from "./r/new"; export default { index: index, view: view, - about: about + about: about, + newpaste: newpaste }; \ No newline at end of file diff --git a/src/routes/r/new.mjs b/src/routes/r/new.mjs new file mode 100644 index 0000000..0bed5c1 --- /dev/null +++ b/src/routes/r/new.mjs @@ -0,0 +1,17 @@ +import express from "express"; +const router = express.Router(); + +import db from "../../lib/sql"; +import * as lib from "../../lib"; + +router.get("/", (req, res) => { + lib.getPaste(1) + .then(row => { + res.send(row); + }) + .catch(err => { + res.send("err"); + }); +}); + +export default router; \ No newline at end of file diff --git a/views/about.handlebars b/views/about.handlebars index 1991675..248a38c 100644 --- a/views/about.handlebars +++ b/views/about.handlebars @@ -1,5 +1,6 @@

About fpaste.cc

-

fpaste.cc is here in it's 1st version – and it's better than expected! A completly written backend in NodeJS makes it possible to develop new features faster than ever before.

+

fpaste.cc is here in it's 1st version – and it's better than expected! A completly backend written in NodeJS makes it possible to develop new features faster than ever before.

With the MariaDB database backend fpaste.cc is even more reliable and the express webserver library offers a powerfull framework.

-

The highlight highlighting engine offers great support for a variety of programming languages.

-

If you're interested in the source code of fpaste.cc, take a look at github.com. If you have any questions/suggestions or would like to contribute to fpaste.cc feel free to contact me.

\ No newline at end of file +

The highlight.js highlighting engine offers great support for a variety of programming languages.

+

If you're interested in the source code of fpaste.cc, take a look at github.com. If you have any questions/suggestions or would like to contribute to fpaste.cc feel free to contact me.

+

project stolen from github.com/mcmaniac/npaste.de

\ No newline at end of file