toggle sfw/nsfw
This commit is contained in:
@ -47,7 +47,11 @@ const flash = ({ type, msg }) => {
|
||||
if(!confirm("Do you really want to delete this tag?"))
|
||||
return;
|
||||
const tagname = e.target.parentElement.querySelector('a:first-child').innerText;
|
||||
const res = await deleteTag(postid, tagname);
|
||||
|
||||
const res = await (await fetch("/api/v2/admin/" + postid + "/tags/" + encodeURIComponent(tagname), {
|
||||
method: 'DELETE'
|
||||
})).json();
|
||||
|
||||
if(!res.success)
|
||||
return alert("uff");
|
||||
tags = res.tags.map(t => t.tag);
|
||||
@ -76,20 +80,7 @@ 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, tagname) => await post("/api/v2/admin/" + postid + "/tags", {
|
||||
tagname: tagname
|
||||
});
|
||||
|
||||
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));
|
||||
_tags.reverse().forEach(tag => {
|
||||
@ -143,7 +134,9 @@ const flash = ({ type, msg }) => {
|
||||
const tmptag = input.value?.trim();
|
||||
if(tags.includes(tmptag))
|
||||
return alert("tag already exists");
|
||||
const res = await addTag(postid, tmptag);
|
||||
const res = await post("/api/v2/admin/" + postid + "/tags", {
|
||||
tagname: tmptag
|
||||
});
|
||||
if(!res.success) {
|
||||
return flash({
|
||||
type: "error",
|
||||
@ -164,7 +157,7 @@ const flash = ({ type, msg }) => {
|
||||
clearTimeout(tt);
|
||||
|
||||
tt = setTimeout(async () => {
|
||||
globalTimeout = null;
|
||||
tt = null;
|
||||
|
||||
const tmptag = input.value?.trim();
|
||||
|
||||
@ -201,23 +194,10 @@ const flash = ({ type, msg }) => {
|
||||
const toggleEvent = async (e = false) => {
|
||||
if(e)
|
||||
e.preventDefault();
|
||||
let res;
|
||||
if(tags.includes("sfw")) {
|
||||
await deleteTag(postid, "sfw");
|
||||
res = await addTag(postid, "nsfw");
|
||||
}
|
||||
else if(tags.includes("nsfw")) {
|
||||
await deleteTag(postid, "nsfw");
|
||||
res = await addTag(postid, "sfw");
|
||||
}
|
||||
else
|
||||
res = await addTag(postid, "sfw");
|
||||
|
||||
if(!res.success)
|
||||
return flash({
|
||||
type: "error",
|
||||
msg: res.msg
|
||||
});
|
||||
|
||||
const res = await (await fetch('/api/v2/admin/' + encodeURIComponent(postid) + '/tags/toggle', {
|
||||
method: 'PUT'
|
||||
})).json();
|
||||
|
||||
renderTags(res.tags);
|
||||
tags = res.tags.map(t => t.tag);
|
||||
@ -233,7 +213,9 @@ const flash = ({ type, msg }) => {
|
||||
e.preventDefault();
|
||||
if(!confirm(`Reason for deleting f0ckpost ${postid} by ${poster} (Weihnachten™)`))
|
||||
return;
|
||||
const res = await deletePost(postid);
|
||||
const res = await post("/api/v2/admin/deletepost", {
|
||||
postid: postid
|
||||
});
|
||||
if(res.success) {
|
||||
flash({
|
||||
type: "success",
|
||||
|
Reference in New Issue
Block a user