diff --git a/public/s/js/admin.js b/public/s/js/admin.js index 1439610..34e835f 100644 --- a/public/s/js/admin.js +++ b/public/s/js/admin.js @@ -89,7 +89,7 @@ const flash = ({ type, msg }) => { const span = document.createElement("span"); span.classList.add("badge", "badge-light", "mr-2"); - span.title = tag.prefix; + span.title = tag.user; if(tag.tag == "sfw") { span.classList.remove("badge-light"); span.classList.add("badge-success"); diff --git a/src/inc/lib.mjs b/src/inc/lib.mjs index 2169813..52f1af5 100644 --- a/src/inc/lib.mjs +++ b/src/inc/lib.mjs @@ -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)+';'); diff --git a/src/inc/routes/apiv2.mjs b/src/inc/routes/apiv2.mjs index c2f0b2a..d992f23 100644 --- a/src/inc/routes/apiv2.mjs +++ b/src/inc/routes/apiv2.mjs @@ -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]) })}); }); diff --git a/src/inc/routes/index.mjs b/src/inc/routes/index.mjs index 4bac490..ebb074b 100644 --- a/src/inc/routes/index.mjs +++ b/src/inc/routes/index.mjs @@ -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(); diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs index 3059d58..6010fee 100644 --- a/src/inc/trigger/parser.mjs +++ b/src/inc/trigger/parser.mjs @@ -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 }); } } diff --git a/src/inc/trigger/tags.mjs b/src/inc/trigger/tags.mjs index ac0e3b0..5fc4165 100644 --- a/src/inc/trigger/tags.mjs +++ b/src/inc/trigger/tags.mjs @@ -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]; diff --git a/views/item.html b/views/item.html index e9bcef0..e5ffe97 100644 --- a/views/item.html +++ b/views/item.html @@ -63,7 +63,7 @@ @if(typeof item.tags !== "undefined") @each(item.tags as tag) - + {{ tag.tag }}@if(session) ×@endif @endeach diff --git a/views/ranking.html b/views/ranking.html index 3ac2814..697380d 100644 --- a/views/ranking.html +++ b/views/ranking.html @@ -3,12 +3,12 @@ rank username - # tagged f0cks + # tags placed @for(let i = 0; i < list.length; i++) {{ i + 1 }} - {!! list[i].prefix !!} + {!! list[i].user !!} {{ list[i].count }} @endfor diff --git a/views/snippets/navbar.html b/views/snippets/navbar.html index 71a112b..bbe053b 100644 --- a/views/snippets/navbar.html +++ b/views/snippets/navbar.html @@ -12,6 +12,7 @@
  • my f0cks
  • settings
  • About
  • +
  • Ranking
  • logout
  • @else