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