querystrings, get, blah
This commit is contained in:
@ -68,7 +68,7 @@ export default (router, tpl) => {
|
||||
});
|
||||
});
|
||||
|
||||
group.get(/\/user\/.*(\/\d+)?$/, async (req, res) => { // auf qs umstellen
|
||||
group.get(/\/user\/.*(\/\d+)?$/, async (req, res) => {
|
||||
const user = req.url.split[3];
|
||||
const eps = +req.url.split[4] || 50;
|
||||
|
||||
@ -85,16 +85,16 @@ export default (router, tpl) => {
|
||||
});
|
||||
|
||||
// adminzeugs
|
||||
group.post(/\/admin\/tags\/add$/, auth, async (req, res) => {
|
||||
if(!req.post.postid || !req.post.tag) {
|
||||
group.get(/\/admin\/tags\/add$/, auth, async (req, res) => {
|
||||
if(!req.url.qs.postid || !req.url.qs.tag) {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: false,
|
||||
msg: "missing postid or tag"
|
||||
})});
|
||||
}
|
||||
|
||||
const postid = +req.post.postid;
|
||||
const tag = req.post.tag?.trim();
|
||||
const postid = +req.url.qs.postid;
|
||||
const tag = req.url.qs.tag?.trim();
|
||||
|
||||
if(tag.length >= 45) {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
@ -130,22 +130,22 @@ export default (router, tpl) => {
|
||||
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: true,
|
||||
postid: req.post.postid,
|
||||
tag: req.post.tag,
|
||||
postid: postid,
|
||||
tag: tag,
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
});
|
||||
|
||||
group.post(/\/admin\/tags\/delete$/, auth, async (req, res) => {
|
||||
if(!req.post.postid || !req.post.tagid) {
|
||||
group.get(/\/admin\/tags\/delete$/, auth, async (req, res) => {
|
||||
if(!req.url.qs.postid || !req.url.qs.tagid) {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: false,
|
||||
msg: "missing postid or tag"
|
||||
})});
|
||||
}
|
||||
|
||||
const postid = +req.post.postid;
|
||||
const tagid = +req.post.tagid;
|
||||
const postid = +req.url.qs.postid;
|
||||
const tagid = +req.url.qs.tagid;
|
||||
|
||||
const tags = await lib.getTags(postid);
|
||||
|
||||
@ -170,13 +170,15 @@ export default (router, tpl) => {
|
||||
})});
|
||||
});
|
||||
|
||||
group.post(/\/admin\/tags\/suggest$/, auth, async (req, res) => {
|
||||
group.get(/\/admin\/tags\/suggest$/, auth, async (req, res) => {
|
||||
const reply = {
|
||||
success: false,
|
||||
suggestions: {}
|
||||
};
|
||||
|
||||
if(req.post?.searchString.length <= 1) {
|
||||
const searchString = req.url.qs.q;
|
||||
|
||||
if(searchString?.length <= 1) {
|
||||
reply.error = 'too short lol';
|
||||
return res.reply({ body: JSON.stringify(reply) });
|
||||
}
|
||||
@ -185,14 +187,13 @@ export default (router, tpl) => {
|
||||
const q = await sql('tags')
|
||||
.select('tag', sql.raw('count(tags_assign.tag_id) as tagged'))
|
||||
.leftJoin('tags_assign', 'tags_assign.tag_id', 'tags.id')
|
||||
.whereRaw("normalized like '%' || slugify(?) || '%'", [ req.post.searchString ])
|
||||
.whereRaw("normalized like '%' || slugify(?) || '%'", [ searchString ])
|
||||
.groupBy('tags.id')
|
||||
.orderBy('tagged', 'desc')
|
||||
.limit(15);
|
||||
reply.success = true;
|
||||
reply.suggestions = q;
|
||||
} catch(err) {
|
||||
reply.success = false;
|
||||
reply.error = err.msg;
|
||||
}
|
||||
|
||||
@ -205,14 +206,14 @@ export default (router, tpl) => {
|
||||
})});
|
||||
});
|
||||
|
||||
group.get(/\/admin\/deletepost\/\d+$/, auth, async (req, res) => {
|
||||
if(!req.url.split[4]) {
|
||||
group.get(/\/admin\/deletepost$/, auth, async (req, res) => {
|
||||
if(!req.url.qs.postid) {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: true,
|
||||
msg: "no postid"
|
||||
})});
|
||||
}
|
||||
const postid = +req.url.split[4];
|
||||
const postid = +req.url.qs.postid;
|
||||
|
||||
await sql("items").where("id", postid).del();
|
||||
res.reply({ body: JSON.stringify({
|
||||
@ -220,19 +221,19 @@ export default (router, tpl) => {
|
||||
})});
|
||||
});
|
||||
|
||||
group.get(/\/admin\/togglefav\/\d+$/, auth, async (req, res) => {
|
||||
const itemid = +req.url.split[4];
|
||||
group.get(/\/admin\/togglefav$/, auth, async (req, res) => {
|
||||
const postid = +req.url.qs.postid;
|
||||
|
||||
let favs = await sql('favorites').select('user_id').where('item_id', itemid);
|
||||
let favs = await sql('favorites').select('user_id').where('item_id', postid);
|
||||
|
||||
if(Object.values(favs).filter(u => u.user_id === req.session.id)[0]) {
|
||||
// del fav
|
||||
await sql('favorites').where('user_id', req.session.id).andWhere('item_id', itemid).del();
|
||||
await sql('favorites').where('user_id', req.session.id).andWhere('item_id', postid).del();
|
||||
}
|
||||
else {
|
||||
// add fav
|
||||
await sql('favorites').insert({
|
||||
item_id: itemid,
|
||||
item_id: postid,
|
||||
user_id: req.session.id
|
||||
});
|
||||
}
|
||||
@ -241,11 +242,11 @@ export default (router, tpl) => {
|
||||
.select('user.user', 'user_options.avatar')
|
||||
.leftJoin('user', 'user.id', 'favorites.user_id')
|
||||
.leftJoin('user_options', 'user_options.user_id', 'favorites.user_id')
|
||||
.where('favorites.item_id', itemid);
|
||||
.where('favorites.item_id', postid);
|
||||
|
||||
res.reply({ body: JSON.stringify({
|
||||
success: true,
|
||||
itemid: itemid,
|
||||
itemid: postid,
|
||||
favs: favs
|
||||
})});
|
||||
});
|
||||
|
Reference in New Issue
Block a user