From d920f430d05403958dccc2c6b0a28358408f133f Mon Sep 17 00:00:00 2001 From: Mast3r_waf1z <32744171+Mast3rwaf1z@users.noreply.github.com> Date: Fri, 1 Mar 2024 00:54:14 +0100 Subject: [PATCH] 29 visitor counter logic isnt correct (#40) * edited index javascript to implement new backend software * edited endpoints to reflect new backend release --- scripts/admin.js | 9 ++++----- scripts/common.js | 8 ++++---- scripts/guestbook.js | 6 +++--- scripts/index.js | 4 ++-- scripts/login.js | 4 ++-- scripts/threads.js | 29 ++++++++++++++--------------- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/scripts/admin.js b/scripts/admin.js index 4bb06e7..200be96 100644 --- a/scripts/admin.js +++ b/scripts/admin.js @@ -6,9 +6,8 @@ var username = document.getElementById("username") console.log(document.cookie) username.innerHTML = getCookie("username") -async function toggleAuth(username, state){ - var api = (await getBackend()) + (state ? "/admin/deauthorize" : "/admin/authorize") - fetch(api, { +async function toggleAuth(username){ + fetch((await getBackend()) +"/admin/users/authorize", { method: "post", body: JSON.stringify({ username: username, @@ -18,7 +17,7 @@ async function toggleAuth(username, state){ } async function deleteUser(username){ - fetch((await getBackend())+"/admin/delete", { + fetch((await getBackend())+"/admin/users/delete", { method: "delete", body: JSON.stringify({ username: username, @@ -29,7 +28,7 @@ async function deleteUser(username){ async function getUsers(){ console.log("getting users") - fetch((await getBackend())+"/admin/users?token="+getCookie("accessToken"), { + fetch((await getBackend())+"/admin/users/get?token="+getCookie("accessToken"), { method:"get" }).then(response => response.json().then(data => { var usersDiv = document.getElementById("users") diff --git a/scripts/common.js b/scripts/common.js index 5e994db..6e146bc 100644 --- a/scripts/common.js +++ b/scripts/common.js @@ -104,7 +104,7 @@ async function makeHeader(){ var newThreadButtonContainer = document.createElement("div") dropdown_content.appendChild(newThreadButtonContainer) - fetch((await getBackend())+"/admin/threads", { + fetch((await getBackend())+"/admin/threads/ids", { method:"get" }).then(response => response.json().then(ids => { ids.forEach(id => { @@ -113,7 +113,7 @@ async function makeHeader(){ dropdown_content.appendChild(button) }) ids.forEach(async id => { - fetch((await getBackend())+"/admin/thread?id="+id, { + fetch((await getBackend())+"/admin/threads/get?id="+id, { method:"get" }).then(response1 => response1.json().then(json => { var name = json["name"] @@ -167,7 +167,7 @@ async function makeHeader(){ newThreadModalPostButton.onclick = async () => { var name = newThreadModalName.value var description = newThreadModalDescription.value - fetch((await getBackend()) + "/admin/newthread", { + fetch((await getBackend()) + "/admin/threads/new", { method: "post", body: JSON.stringify({ token: getCookie("accessToken"), @@ -224,7 +224,7 @@ async function verify(){ if(getCookie("verified") == "true"){ return true } - return await fetch((await getBackend()) + "/admin/verify", { + return await fetch((await getBackend()) + "/admin/tokens/verify", { method: "post", body: JSON.stringify({ token:getCookie("accessToken") diff --git a/scripts/guestbook.js b/scripts/guestbook.js index 21367f7..6e53844 100644 --- a/scripts/guestbook.js +++ b/scripts/guestbook.js @@ -12,7 +12,7 @@ async function post(){ console.log(message) console.log(name) console.log(time) - fetch((await getBackend())+"/admin/guestbook", { + fetch((await getBackend())+"/admin/guestbook/new", { method: "post", body: JSON.stringify({ message: message, @@ -38,7 +38,7 @@ async function post(){ } async function generateEntry(id){ - await fetch((await getBackend())+"/admin/guestbook?id="+id, { + await fetch((await getBackend())+"/admin/guestbook/get?id="+id, { method: "get" }).then(response => { switch(response.status){ @@ -90,7 +90,7 @@ async function generateGuestbook(data){ } async function doGuestbook(){ - fetch((await getBackend())+"/admin/guestbook", { + fetch((await getBackend())+"/admin/guestbook/ids", { method: "get" }).then(response => { switch(response.status){ diff --git a/scripts/index.js b/scripts/index.js index eff1d1d..0b2100a 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,7 +1,7 @@ async function doVisit(){ - fetch((await getBackend())+"/admin/visit", { + fetch((await getBackend())+"/admin/visits/get", { method:"get" }).then(response => { switch(response.status){ @@ -50,7 +50,7 @@ async function commit_history(){ async function getSessionToken(){ if(getCookie("session") == ""){ - fetch((await getBackend())+"/admin/session", { + fetch((await getBackend())+"/admin/visits/new", { method:"post" }).then(response => response.text().then(token => { var date = new Date() diff --git a/scripts/login.js b/scripts/login.js index 54d30be..ee6a479 100644 --- a/scripts/login.js +++ b/scripts/login.js @@ -9,7 +9,7 @@ function showPassword(){ }; async function login(){ - fetch((await getBackend())+"/admin/auth", { + fetch((await getBackend())+"/admin/users/verify", { method: "post", body: JSON.stringify({ username: document.getElementById("username").value, @@ -41,7 +41,7 @@ async function login(){ } async function register(){ - fetch((await getBackend())+"/admin/register", { + fetch((await getBackend())+"/admin/users/register", { method: "post", body: JSON.stringify({ username: document.getElementById("username").value, diff --git a/scripts/threads.js b/scripts/threads.js index 04a4c8e..d3411bd 100644 --- a/scripts/threads.js +++ b/scripts/threads.js @@ -4,7 +4,7 @@ var container = document.getElementById("posts-container") var id = getCookie("currentThread") async function setGeneral(){ - fetch((await getBackend()) + "/admin/thread?id="+id, { + fetch((await getBackend()) + "/admin/threads/get?id="+id, { method: "get" }).then(response => response.json().then(json => { header.innerHTML = json.name @@ -22,16 +22,15 @@ function reorderPosts(posts){ async function setPosts(){ // fuckit rewrite - fetch((await getBackend()) + "/admin/posts?id="+id, { + fetch((await getBackend()) + "/admin/posts/ids?id="+id, { method: "get" }).then(response => response.json().then(postsData => reorderPosts(postsData).forEach(async postData => { - console.log(postsData) var postId = postData.id var postPriority = postData.value == null ? 0 : postData.value var div = document.createElement("div") div.className = "post" container.insertChildAtIndex(div, postId) - fetch((await getBackend()) + "/admin/post?id="+postId, {method:"get"}).then(response1 => response1.json().then(json => { + fetch((await getBackend()) + "/admin/posts/get?id="+postId, {method:"get"}).then(response1 => response1.json().then(json => { var inner = document.createElement("div") div.appendChild(inner) div.appendChild(document.createElement("br")) @@ -42,7 +41,7 @@ async function setPosts(){ var deleteButton = document.createElement("button") deleteButton.innerHTML = "Delete" deleteButton.onclick = async () => { - fetch((await getBackend())+"/admin/post", { + fetch((await getBackend())+"/admin/posts/delete", { method: "delete", body: JSON.stringify({ token: getCookie("accessToken"), @@ -64,7 +63,7 @@ async function setPosts(){ var incrementButton = document.createElement("button") incrementButton.innerHTML = "Increment" incrementButton.onclick = async _ => { - fetch((await getBackend())+"/admin/setpriority",{ + fetch((await getBackend())+"/admin/posts/order",{ method: "post", body:JSON.stringify({ "token":getCookie("accessToken"), @@ -78,7 +77,7 @@ async function setPosts(){ var decrementButton = document.createElement("button") decrementButton.innerHTML = "Decrement" decrementButton.onclick = async _ => { - fetch((await getBackend())+"/admin/setpriority",{ + fetch((await getBackend())+"/admin/order",{ method: "post", body:JSON.stringify({ "token":getCookie("accessToken"), @@ -97,8 +96,8 @@ async function addButtonsIfAdmin(){ if(await verify()){ document.getElementById("top-editor").style.display = "inline" var imagesContainer = document.getElementById("images") - fetch((await getBackend()) + "/admin/images", { - method: "get", + fetch((await getBackend()) + "/admin/posts/images/all?token="+getCookie("accessToken"), { + method: "get" }).then(response => response.json().then(json => json.forEach(async path => { var imageContainer = document.createElement("div") var button = document.createElement("button") @@ -112,7 +111,7 @@ async function addButtonsIfAdmin(){ imageContainer.appendChild(a) imageContainer.style.padding = "5px" button.onclick = async () => { - fetch((await getBackend()) + "/admin/images", { + fetch((await getBackend()) + "/admin/posts/images/delete", { method: "delete", body: JSON.stringify({ token: getCookie("accessToken"), @@ -139,7 +138,7 @@ document.getElementById("create-button").onclick = () => { } document.getElementById("delete-button").onclick = async () => { - fetch((await getBackend()) + "/admin/thread", { + fetch((await getBackend()) + "/admin/threads/delete", { method:"delete", body: JSON.stringify({ token:getCookie("accessToken"), @@ -156,7 +155,7 @@ document.getElementById("edit-button").onclick = async () => { } document.getElementById("edit-post-button").onclick = async () => { - fetch((await getBackend()) + "/admin/editpost", { + fetch((await getBackend()) + "/admin/posts/edit", { method: "post", body: JSON.stringify({ html: document.getElementById("edit-post-content").value, @@ -169,7 +168,7 @@ document.getElementById("edit-post-button").onclick = async () => { document.getElementById("post-button").onclick = async () => { var html = document.getElementById("new-post-content").value - fetch((await getBackend()) + "/admin/post", { + fetch((await getBackend()) + "/admin/posts/new", { method: "post", body: JSON.stringify({ token: getCookie("accessToken"), @@ -182,7 +181,7 @@ document.getElementById("post-button").onclick = async () => { document.getElementById("edit-confirm").onclick = async () => { var name = document.getElementById("edit-thread-name").value var description = document.getElementById("edit-thread-description").value - fetch((await getBackend()) + "/admin/editthread", { + fetch((await getBackend()) + "/admin/threads/edit", { method: "post", body: JSON.stringify({ id: id, @@ -197,7 +196,7 @@ document.getElementById("image-upload-button").onclick = async () => { var file = document.getElementById("image-upload").files[0] if(["image/png", "image/jpg", "image/jpeg", "image/gif"].includes(file.type)){ document.getElementById("image-upload-status").innerHTML = "uploading..." - fetch((await getBackend()) + "/admin/image?token="+getCookie("accessToken")+"&filename="+file.name, { + fetch((await getBackend()) + "/admin/posts/images/new?token="+getCookie("accessToken")+"&filename="+file.name, { method: "put", body: file }).finally(_ => {