From 9a3b494a94cf821a3c0ed24650579870ac29a8a4 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 25 Dec 2021 13:12:53 +0100 Subject: [PATCH] tagid instead of tagname --- public/s/js/admin.js | 16 +++++++++------- src/inc/routes/apiv2.mjs | 10 ++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/public/s/js/admin.js b/public/s/js/admin.js index 34e835f..b928570 100644 --- a/public/s/js/admin.js +++ b/public/s/js/admin.js @@ -46,10 +46,10 @@ const flash = ({ type, msg }) => { e.preventDefault(); if(!confirm("Do you really want to delete this tag?")) return; - const tag = e.target.parentElement.innerText.slice(0, -2); - if(!tags.includes(tag)) - return alert("wtf"); - const res = await deleteTag(postid, tag); + const tagid = +e.target.parentElement.dataset.tagid; + /*if(!tags.includes(tag)) + return alert("wtf");*/ + const res = await deleteTag(postid, tagid); if(!res.success) return alert("uff"); tags = res.tags.map(t => t.tag); @@ -73,9 +73,9 @@ const flash = ({ type, msg }) => { tag: tag })).json(); - const deleteTag = async (postid, tag) => await (await post("/api/v2/admin/tags/delete", { + const deleteTag = async (postid, tagid) => await (await post("/api/v2/admin/tags/delete", { postid: postid, - tag: tag + tagid: tagid })).json(); const renderTags = _tags => { @@ -85,11 +85,13 @@ const flash = ({ type, msg }) => { a.href = `/tag/${tag.tag}`; a.target = "_blank"; a.style = "color: inherit !important"; - a.innerText = tag.tag; + a.innerHTML = tag.tag; const span = document.createElement("span"); span.classList.add("badge", "badge-light", "mr-2"); span.title = tag.user; + span.dataset.tagid = tag.id; + if(tag.tag == "sfw") { span.classList.remove("badge-light"); span.classList.add("badge-success"); diff --git a/src/inc/routes/apiv2.mjs b/src/inc/routes/apiv2.mjs index d992f23..427a5ea 100644 --- a/src/inc/routes/apiv2.mjs +++ b/src/inc/routes/apiv2.mjs @@ -136,7 +136,7 @@ export default (router, tpl) => { }); group.post(/\/admin\/tags\/delete$/, auth, async (req, res) => { - if(!req.post.postid || !req.post.tag) { + if(!req.post.postid || !req.post.tagid) { return res.reply({ body: JSON.stringify({ success: false, msg: "missing postid or tag" @@ -144,15 +144,14 @@ export default (router, tpl) => { } const postid = +req.post.postid; - const tag = req.post.tag; + const tagid = +req.post.tagid; const tags = await lib.getTags(postid); - const tagid = tags.filter(t => t.tag === tag)[0]?.id ?? null; - if(!tagid || tagid?.length === 0) { + const tagcheck = tags.filter(t => t.id === tagid)[0]?.id ?? null; + if(!tagcheck || !tagid || tagid?.length === 0) { return res.reply({ body: JSON.stringify({ success: false, - tag: tag, msg: "tag is not assigned", tags: await lib.getTags(postid) })}); @@ -165,7 +164,6 @@ export default (router, tpl) => { return res.reply({ body: JSON.stringify({ success: reply, - tag: tag, tagid: tagid, tags: await lib.getTags(postid) })});