new pastes
This commit is contained in:
parent
22211749dd
commit
96ae3cac24
|
@ -1,12 +1,10 @@
|
||||||
import index from "./r/index";
|
import index from "./r/index";
|
||||||
import view from "./r/view";
|
import view from "./r/view";
|
||||||
import about from "./r/about";
|
import about from "./r/about";
|
||||||
import newpaste from "./r/new";
|
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
index: index,
|
index: index,
|
||||||
view: view,
|
view: view,
|
||||||
about: about,
|
about: about
|
||||||
newpaste: newpaste
|
|
||||||
};
|
};
|
|
@ -1,11 +1,15 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
export default express.Router()
|
||||||
res.render("about");
|
.get("/", (req, res) => {
|
||||||
});
|
res.render("about");
|
||||||
router.get("/howto", (req, res) => {
|
})
|
||||||
res.render("howto");
|
.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";
|
import db from "../../lib/sql";
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
const query = "insert into `pastes` (`uuid`,`lang`,`desc`,`paste`,`hidden`,`reply`) "
|
||||||
db.exec("select * from `languages`")
|
+ "values (LEFT(UUID(), 8), ?, ?, ?, ?, ?)";
|
||||||
.then(rows => {
|
let languages = new Map();
|
||||||
res.render("index", { languages: rows.map(r => r.name) } )
|
db.exec("select * from `languages`")
|
||||||
})
|
.then(rows => rows.forEach(r => languages.set(r.id, r.name)))
|
||||||
.catch(err => {
|
.catch(err => console.log(err));
|
||||||
res.send(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