toggle sfw/nsfw
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user