xD
This commit is contained in:
parent
f8fbcf0384
commit
ed179b004d
|
@ -1,19 +1,20 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
import db from "../../lib/sql";
|
import db from "../../lib/sql";
|
||||||
|
|
||||||
const query = "insert into `pastes` (`uuid`,`lang`,`desc`,`paste`,`hidden`,`reply`) "
|
const queries = {
|
||||||
+ "values (LEFT(UUID(), 8), ?, ?, ?, ?, ?)";
|
getlangs: "select * from `languages`",
|
||||||
|
add: "insert into `pastes` (`uuid`,`lang`,`desc`,`paste`,`hidden`,`reply`) "
|
||||||
|
+ "values (LEFT(UUID(), 8), ?, ?, ?, ?, ?)",
|
||||||
|
getuuid: "select `uuid` from `pastes` where `id` = ? limit 1"
|
||||||
|
};
|
||||||
let languages = new Map();
|
let languages = new Map();
|
||||||
db.exec("select * from `languages`")
|
db.exec(queries.getlangs)
|
||||||
.then(rows => rows.forEach(r => languages.set(r.id, r.name)))
|
.then(rows => rows.forEach(r => languages.set(r.id, r.name)))
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
export default express.Router()
|
export default express.Router()
|
||||||
.get("/", (req, res) => {
|
.get("/", (req, res) => res.render("index", { languages: [...languages.values()] }))
|
||||||
res.render("index", { languages: [...languages.values()] } )
|
|
||||||
})
|
|
||||||
.post("/", (req, res) => {
|
.post("/", (req, res) => {
|
||||||
const data = {
|
const data = {
|
||||||
desc: req.body.desc || "",
|
desc: req.body.desc || "",
|
||||||
|
@ -24,17 +25,16 @@ export default express.Router()
|
||||||
};
|
};
|
||||||
if(!data.content)
|
if(!data.content)
|
||||||
return res.render("index", { languages: [...languages.values()], notification: "nope" });
|
return res.render("index", { languages: [...languages.values()], notification: "nope" });
|
||||||
db.exec(query, [
|
db.exec(queries.add, [
|
||||||
data.lang,
|
data.lang,
|
||||||
data.desc,
|
data.desc,
|
||||||
new Buffer(data.content).toString("base64"),
|
new Buffer(data.content).toString("base64"),
|
||||||
data.hidden,
|
data.hidden,
|
||||||
data.reply
|
data.reply
|
||||||
]).then(insert => {
|
]).then(insert => db.exec(queries.getuuid, [insert.insertId])
|
||||||
db.exec("select `uuid` from `pastes` where `id` = ? limit 1", [insert.insertId]).then(rows => {
|
.then(rows => res.redirect(`/${rows[0].uuid}/`))
|
||||||
res.redirect(`/${rows[0].uuid}/`);
|
.catch(err => res.render("index", { languages: [...languages.values()], notification: "lol" }))
|
||||||
}).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" }));
|
||||||
}).catch(err => res.render("index", { languages: [...languages.values()], notification: "didn't insert your paste lol" }));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Map.prototype.getKey = function(val) {
|
Map.prototype.getKey = function(val) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user