This commit is contained in:
Flummi
2022-03-24 16:13:51 +01:00
parent abcea99fe0
commit 9c516f7712
2 changed files with 38 additions and 22 deletions

View File

@ -54,23 +54,39 @@ const flash = ({ type, msg }) => {
renderTags(res.tags);
};
const get = async (url, data) => {
let s = [];
for(const [ key, val ] of Object.entries(data))
s.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
return (await fetch(url + "?" + s.join("&"))).json();
const queryapi = async (url, data, method = 'GET') => {
let req;
if(method == 'POST') {
req = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
}
else {
let s = [];
for(const [ key, val ] of Object.entries(data))
s.push(encodeURIComponent(key) + "=" + encodeURIComponent(val));
req = await fetch(url + '?' + s.join('&'));
}
return await req.json();
};
const deletePost = async postid => await get("/api/v2/admin/deletepost", {
const get = async (url, data) => queryapi(url, data, 'GET');
const post = async (url, data) => queryapi(url, data, 'POST');
const deletePost = async postid => await post("/api/v2/admin/deletepost", {
postid: postid
});
const addTag = async (postid, tag) => await get("/api/v2/admin/tags/add", {
const addTag = async (postid, tag) => await post("/api/v2/admin/tags/add", {
postid: postid,
tag: tag
});
const deleteTag = async (postid, tagid) => await get("/api/v2/admin/tags/delete", {
const deleteTag = async (postid, tagid) => await post("/api/v2/admin/tags/delete", {
postid: postid,
tagid: tagid
});
@ -235,7 +251,7 @@ const flash = ({ type, msg }) => {
};
const toggleFavEvent = async e => {
const res = await get('/api/v2/admin/togglefav', {
const res = await post('/api/v2/admin/togglefav', {
postid: postid
});
if(res.success) {