tagid instead of tagname

This commit is contained in:
Flummi 2021-12-25 13:12:53 +01:00
parent d71eece80e
commit 9a3b494a94
2 changed files with 13 additions and 13 deletions

View File

@ -46,10 +46,10 @@ const flash = ({ type, msg }) => {
e.preventDefault(); e.preventDefault();
if(!confirm("Do you really want to delete this tag?")) if(!confirm("Do you really want to delete this tag?"))
return; return;
const tag = e.target.parentElement.innerText.slice(0, -2); const tagid = +e.target.parentElement.dataset.tagid;
if(!tags.includes(tag)) /*if(!tags.includes(tag))
return alert("wtf"); return alert("wtf");*/
const res = await deleteTag(postid, tag); const res = await deleteTag(postid, tagid);
if(!res.success) if(!res.success)
return alert("uff"); return alert("uff");
tags = res.tags.map(t => t.tag); tags = res.tags.map(t => t.tag);
@ -73,9 +73,9 @@ const flash = ({ type, msg }) => {
tag: tag tag: tag
})).json(); })).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, postid: postid,
tag: tag tagid: tagid
})).json(); })).json();
const renderTags = _tags => { const renderTags = _tags => {
@ -85,11 +85,13 @@ const flash = ({ type, msg }) => {
a.href = `/tag/${tag.tag}`; a.href = `/tag/${tag.tag}`;
a.target = "_blank"; a.target = "_blank";
a.style = "color: inherit !important"; a.style = "color: inherit !important";
a.innerText = tag.tag; a.innerHTML = tag.tag;
const span = document.createElement("span"); const span = document.createElement("span");
span.classList.add("badge", "badge-light", "mr-2"); span.classList.add("badge", "badge-light", "mr-2");
span.title = tag.user; span.title = tag.user;
span.dataset.tagid = tag.id;
if(tag.tag == "sfw") { if(tag.tag == "sfw") {
span.classList.remove("badge-light"); span.classList.remove("badge-light");
span.classList.add("badge-success"); span.classList.add("badge-success");

View File

@ -136,7 +136,7 @@ export default (router, tpl) => {
}); });
group.post(/\/admin\/tags\/delete$/, auth, async (req, res) => { 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({ return res.reply({ body: JSON.stringify({
success: false, success: false,
msg: "missing postid or tag" msg: "missing postid or tag"
@ -144,15 +144,14 @@ export default (router, tpl) => {
} }
const postid = +req.post.postid; const postid = +req.post.postid;
const tag = req.post.tag; const tagid = +req.post.tagid;
const tags = await lib.getTags(postid); const tags = await lib.getTags(postid);
const tagid = tags.filter(t => t.tag === tag)[0]?.id ?? null; const tagcheck = tags.filter(t => t.id === tagid)[0]?.id ?? null;
if(!tagid || tagid?.length === 0) { if(!tagcheck || !tagid || tagid?.length === 0) {
return res.reply({ body: JSON.stringify({ return res.reply({ body: JSON.stringify({
success: false, success: false,
tag: tag,
msg: "tag is not assigned", msg: "tag is not assigned",
tags: await lib.getTags(postid) tags: await lib.getTags(postid)
})}); })});
@ -165,7 +164,6 @@ export default (router, tpl) => {
return res.reply({ body: JSON.stringify({ return res.reply({ body: JSON.stringify({
success: reply, success: reply,
tag: tag,
tagid: tagid, tagid: tagid,
tags: await lib.getTags(postid) tags: await lib.getTags(postid)
})}); })});