tags_assign: user_id instead of prefix
This commit is contained in:
@ -99,7 +99,9 @@ export default new class {
|
||||
};
|
||||
async getTags(itemid) {
|
||||
const tags = await sql("tags_assign")
|
||||
.select("tags.id", "tags.tag", "user.user")
|
||||
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
||||
.leftJoin("user", "user.id", "tags_assign.user_id")
|
||||
.where("tags_assign.item_id", itemid);
|
||||
for(let t = 0; t < tags.length; t++)
|
||||
tags[t].tag = tags[t].tag.replace(/[\u00A0-\u9999<>\&]/g, i => '&#'+i.charCodeAt(0)+';');
|
||||
|
@ -1,4 +1,5 @@
|
||||
import sql from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
|
||||
const allowedMimes = [ "audio", "image", "video", "%" ];
|
||||
const auth = async (req, res, next) => {
|
||||
@ -11,11 +12,6 @@ const auth = async (req, res, next) => {
|
||||
return next();
|
||||
};
|
||||
|
||||
const getTags = async itemid => await sql("tags_assign")
|
||||
.leftJoin("tags", "tags.id", "tags_assign.tag_id")
|
||||
.where("tags_assign.item_id", itemid)
|
||||
.select("tags.id", "tags.tag", "tags_assign.prefix");
|
||||
|
||||
export default (router, tpl) => {
|
||||
router.group(/^\/api\/v2/, group => {
|
||||
|
||||
@ -121,13 +117,13 @@ export default (router, tpl) => {
|
||||
await sql("tags_assign").insert({
|
||||
tag_id: tagid,
|
||||
item_id: postid,
|
||||
prefix: `${req.session.user}@webinterface`
|
||||
user_id: req.session.id
|
||||
});
|
||||
} catch(err) {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: false,
|
||||
msg: err.message,
|
||||
tags: await getTags(postid)
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
}
|
||||
|
||||
@ -135,7 +131,7 @@ export default (router, tpl) => {
|
||||
success: true,
|
||||
postid: req.post.postid,
|
||||
tag: req.post.tag,
|
||||
tags: await getTags(postid)
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
});
|
||||
|
||||
@ -150,7 +146,7 @@ export default (router, tpl) => {
|
||||
const postid = +req.post.postid;
|
||||
const tag = req.post.tag;
|
||||
|
||||
const tags = await getTags(postid);
|
||||
const tags = await lib.getTags(postid);
|
||||
|
||||
const tagid = tags.filter(t => t.tag === tag)[0]?.id ?? null;
|
||||
if(!tagid || tagid?.length === 0) {
|
||||
@ -158,28 +154,26 @@ export default (router, tpl) => {
|
||||
success: false,
|
||||
tag: tag,
|
||||
msg: "tag is not assigned",
|
||||
tags: await getTags(postid)
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
}
|
||||
|
||||
let q = sql("tags_assign").where("tag_id", tagid).andWhere("item_id", postid).del();
|
||||
if(req.session.level < 50)
|
||||
q = q.andWhere("prefix", `${req.session.user}@webinterface`);
|
||||
q = q.andWhere("user_id", req.session.id);
|
||||
const reply = !!(await q);
|
||||
|
||||
//await cleanTags();
|
||||
|
||||
|
||||
return res.reply({ body: JSON.stringify({
|
||||
success: reply,
|
||||
tag: tag,
|
||||
tagid: tagid,
|
||||
tags: await getTags(postid)
|
||||
tags: await lib.getTags(postid)
|
||||
})});
|
||||
});
|
||||
|
||||
group.get(/\/admin\/tags\/get\/\d+$/, auth, async (req, res) => {
|
||||
return res.reply({ body: JSON.stringify({
|
||||
tags: await getTags(+req.url.split[5])
|
||||
tags: await lib.getTags(+req.url.split[5])
|
||||
})});
|
||||
});
|
||||
|
||||
|
@ -231,8 +231,9 @@ export default (router, tpl) => {
|
||||
router.get(/^\/ranking/, async (req, res) => {
|
||||
try {
|
||||
const list = await sql('tags_assign')
|
||||
.select('prefix', sql.raw('count(distinct tag_id, item_id) count'))
|
||||
.groupBy('prefix')
|
||||
.select('user.user', sql.raw('count(distinct tag_id, item_id) count'))
|
||||
.leftJoin('user', 'user.id', 'tags_assign.user_id')
|
||||
.groupBy('user.user')
|
||||
.orderBy('count', 'desc');
|
||||
|
||||
const stats = await lib.countf0cks();
|
||||
|
@ -165,7 +165,7 @@ export default async bot => {
|
||||
await sql("tags_assign").insert({
|
||||
tag_id: tag === "sfw" ? 1 : 2,
|
||||
item_id: insertq,
|
||||
prefix: `autotagger`
|
||||
user_id: 7 // user: autotagger
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export default async bot => {
|
||||
}, {
|
||||
name: "tags add",
|
||||
call: /^\!tags add \d+ .*/i,
|
||||
active: true,
|
||||
active: false,
|
||||
level: 100,
|
||||
f: async e => {
|
||||
const id = +e.args[1];
|
||||
@ -71,7 +71,7 @@ export default async bot => {
|
||||
}, {
|
||||
name: "tags remove",
|
||||
call: /^\!tags remove \d+ .*/i,
|
||||
active: true,
|
||||
active: false,
|
||||
level: 100,
|
||||
f: async e => {
|
||||
const id = +e.args[1];
|
||||
|
Reference in New Issue
Block a user