new pastes
This commit is contained in:
parent
22211749dd
commit
96ae3cac24
|
@ -1,12 +1,10 @@
|
|||
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,
|
||||
newpaste: newpaste
|
||||
about: about
|
||||
};
|
|
@ -1,11 +1,15 @@
|
|||
import express from "express";
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
export default express.Router()
|
||||
.get("/", (req, res) => {
|
||||
res.render("about");
|
||||
});
|
||||
router.get("/howto", (req, res) => {
|
||||
})
|
||||
.get("/howto", (req, res) => {
|
||||
res.render("howto");
|
||||
});
|
||||
|
||||
export default router;
|
||||
})
|
||||
.get("/contact", (req, res) => {
|
||||
res.render("contact");
|
||||
})
|
||||
.get("/statistics", (req, res) => {
|
||||
res.render("statistics");
|
||||
});
|
|
@ -3,14 +3,43 @@ const router = express.Router();
|
|||
|
||||
import db from "../../lib/sql";
|
||||
|
||||
router.get("/", (req, res) => {
|
||||
db.exec("select * from `languages`")
|
||||
.then(rows => {
|
||||
res.render("index", { languages: rows.map(r => r.name) } )
|
||||
})
|
||||
.catch(err => {
|
||||
res.send(err);
|
||||
});
|
||||
});
|
||||
const query = "insert into `pastes` (`uuid`,`lang`,`desc`,`paste`,`hidden`,`reply`) "
|
||||
+ "values (LEFT(UUID(), 8), ?, ?, ?, ?, ?)";
|
||||
let languages = new Map();
|
||||
db.exec("select * from `languages`")
|
||||
.then(rows => rows.forEach(r => languages.set(r.id, r.name)))
|
||||
.catch(err => console.log(err));
|
||||
|
||||
export default router;
|
||||
export default express.Router()
|
||||
.get("/", (req, res) => {
|
||||
res.render("index", { languages: [...languages.values()] } )
|
||||
})
|
||||
.post("/", (req, res) => {
|
||||
const data = {
|
||||
desc: req.body.desc || null,
|
||||
content: req.body.content || false,
|
||||
lang: languages.getKey(req.body.lang) || 1,
|
||||
hidden: req.body.hidden || 0,
|
||||
reply: req.body.reply || 0
|
||||
};
|
||||
if(!data.content)
|
||||
return res.render("index", { languages: [...languages.values()], notification: "nope" });
|
||||
db.exec(query, [
|
||||
data.lang,
|
||||
data.desc,
|
||||
new Buffer(data.content).toString("base64"),
|
||||
data.hidden,
|
||||
data.reply
|
||||
]).then(insert => {
|
||||
db.exec("select `uuid` from `pastes` where `id` = ? limit 1", [insert.insertId]).then(rows => {
|
||||
res.redirect(`/${rows[0].uuid}/`);
|
||||
}).catch(err => res.render("index", { languages: [...languages.values()], notification: "lol" }));
|
||||
}).catch(err => res.render("index", { languages: [...languages.values()], notification: "didn't insert your paste lol" }));
|
||||
});
|
||||
|
||||
Map.prototype.getKey = function(val) {
|
||||
for (let [key, value] of this)
|
||||
if(value.toLowerCase() === val.toLowerCase())
|
||||
return key;
|
||||
return false;
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
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;
|
Loading…
Reference in New Issue
Block a user