api schmapi

This commit is contained in:
Flummi
2022-03-24 20:29:20 +01:00
parent 06850f96c1
commit e0c7f3971c
3 changed files with 66 additions and 57 deletions

View File

@ -46,8 +46,8 @@ const flash = ({ type, msg }) => {
e.preventDefault();
if(!confirm("Do you really want to delete this tag?"))
return;
const tagid = +e.target.parentElement.dataset.tagid;
const res = await deleteTag(postid, tagid);
const tagname = e.target.parentElement.querySelector('a:first-child').innerText;
const res = await deleteTag(postid, tagname);
if(!res.success)
return alert("uff");
tags = res.tags.map(t => t.tag);
@ -76,20 +76,19 @@ const flash = ({ type, msg }) => {
const get = async (url, data) => queryapi(url, data, 'GET');
const post = async (url, data) => queryapi(url, data, 'POST');
const del = async (url, data) => queryapi(url, data, 'DELETE');
const deletePost = async postid => await post("/api/v2/admin/deletepost", {
postid: postid
});
const addTag = async (postid, tag) => await post("/api/v2/admin/tags/add", {
postid: postid,
tag: tag
const addTag = async (postid, tagname) => await post("/api/v2/admin/" + postid + "/tags", {
tagname: tagname
});
const deleteTag = async (postid, tagid) => await post("/api/v2/admin/tags/delete", {
postid: postid,
tagid: tagid
});
const deleteTag = async (postid, tagname) => await (await fetch("/api/v2/admin/" + postid + "/tags/" + encodeURIComponent(tagname), {
method: 'DELETE'
})).json();
const renderTags = _tags => {
[...document.querySelectorAll("#tags > .badge")].forEach(tag => tag.parentElement.removeChild(tag));
@ -102,7 +101,6 @@ const flash = ({ type, msg }) => {
const span = document.createElement("span");
span.classList.add("badge", "mr-2");
span.setAttribute('tooltip', tag.user);
span.dataset.tagid = tag.id;
tag.badge.split(" ").forEach(b => span.classList.add(b));
@ -205,11 +203,11 @@ const flash = ({ type, msg }) => {
e.preventDefault();
let res;
if(tags.includes("sfw")) {
await deleteTag(postid, 1);
await deleteTag(postid, "sfw");
res = await addTag(postid, "nsfw");
}
else if(tags.includes("nsfw")) {
await deleteTag(postid, 2);
await deleteTag(postid, "nsfw");
res = await addTag(postid, "sfw");
}
else