Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
29 visitor counter logic isnt correct (#40)
Browse files Browse the repository at this point in the history
* edited index javascript to implement new backend software

* edited endpoints to reflect new backend release
  • Loading branch information
Mast3rwaf1z authored Feb 29, 2024
1 parent a0a00fa commit d920f43
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
9 changes: 4 additions & 5 deletions scripts/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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"]
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions scripts/guestbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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){
Expand Down Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions scripts/index.js
Original file line number Diff line number Diff line change
@@ -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){
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions scripts/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 14 additions & 15 deletions scripts/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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")
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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(_ => {
Expand Down

0 comments on commit d920f43

Please sign in to comment.