tag suggestions
This commit is contained in:
@ -98,7 +98,7 @@ export default new class {
|
||||
};
|
||||
async getTags(itemid) {
|
||||
const tags = await sql("tags_assign")
|
||||
.select("tags.id", "tags.tag", "user.user")
|
||||
.select("tags.id", "tags.tag", "tags.normalized", "user.user")
|
||||
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
||||
.leftJoin("user", "user.id", "tags_assign.user_id")
|
||||
.where("tags_assign.item_id", itemid)
|
||||
|
@ -163,18 +163,41 @@ export default (router, tpl) => {
|
||||
q = q.andWhere("user_id", req.session.id);
|
||||
const reply = !!(await q);
|
||||
|
||||
/*await sql('tags') // delete unused tags
|
||||
.whereNotIn('id', sql('tags_assign').select('tag_id'))
|
||||
.andWhereNot('tag', 'sfw')
|
||||
.andWhereNot('tag', 'nsfw')
|
||||
.del();*/
|
||||
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: reply,
|
||||
tagid: tagid,
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
});
|
||||
|
||||
group.post(/\/admin\/tags\/suggest$/, auth, async (req, res) => {
|
||||
const reply = {
|
||||
success: false,
|
||||
suggestions: {}
|
||||
};
|
||||
|
||||
if(req.post?.searchString.length <= 1) {
|
||||
reply.error = 'too short lol';
|
||||
return res.reply({ body: JSON.stringify(reply) });
|
||||
}
|
||||
|
||||
try {
|
||||
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 ])
|
||||
.groupBy('tags.id')
|
||||
.orderBy('tagged', 'desc')
|
||||
.limit(15);
|
||||
reply.success = true;
|
||||
reply.suggestions = q;
|
||||
} catch(err) {
|
||||
reply.success = false;
|
||||
reply.error = err.msg;
|
||||
}
|
||||
|
||||
return res.reply({ body: JSON.stringify(reply) });
|
||||
});
|
||||
|
||||
group.get(/\/admin\/tags\/get\/\d+$/, auth, async (req, res) => {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
|
Reference in New Issue
Block a user