toggle sfw/nsfw

This commit is contained in:
Flummi
2022-03-25 15:24:12 +01:00
parent 81adcde556
commit e15c16434c
2 changed files with 50 additions and 34 deletions

View File

@ -187,6 +187,40 @@ export default (router, tpl) => {
})});
});
group.put(/\/admin\/(?<postid>\d+)\/tags\/toggle$/, auth, async (req, res) => {
// xD
if(!req.params.postid) {
return res.json({
success: false,
msg: "missing postid"
});
}
const postid = +req.params.postid;
if(!(await lib.getTags(postid)).filter(tag => [1,2].includes(tag.id)).length) {
// insert
await sql('tags_assign').insert({
item_id: postid,
tag_id: 1,
user_id: req.session.id
});
}
else {
// update
await sql('tags_assign')
.update({
tag_id: sql.raw('(array[2,1])[tag_id]')
})
.whereRaw('tag_id = any(array[1,2])')
.andWhere('item_id', postid);
}
return res.reply({ body: JSON.stringify({
tags: await lib.getTags(postid)
})});
});
group.get(/\/admin\/tags\/suggest$/, auth, async (req, res) => {
const reply = {
success: false,