This commit is contained in:
maaa 2023-07-22 18:15:59 +02:00
parent 497b25915a
commit 37dfef84f5
7 changed files with 132 additions and 2 deletions

View File

@ -2,3 +2,4 @@
HOST = 0.0.0.0
PORT = 8080
SECRET_KEY = placeholder
MAX_STORAGE = 25000000

17
main
View File

@ -14,6 +14,7 @@ config.read("config.ini")
HOST = config["config"]["HOST"]
PORT = config["config"]["PORT"]
SECRET_KEY = config["config"]["SECRET_KEY"]
MAX_STORAGE = config["config"]["MAX_STORAGE"]
if SECRET_KEY == "placeholder":
print("[WARNING] Secret key not set")
@ -46,6 +47,15 @@ def get_note(id):
return "error"
return post
def get_space(id):
conn = get_db_connection()
notes = conn.execute("SELECT content FROM notes WHERE creator = ? ORDER BY id DESC;", (id,)).fetchall()
conn.close()
spacetaken = 0
for x in notes:
spacetaken = spacetaken + len(x["content"].encode("utf-8"))
return spacetaken
def get_session(id):
conn = get_db_connection()
post = conn.execute("SELECT * FROM sessions WHERE session = ?",
@ -171,7 +181,9 @@ def apiuserinfo():
datatemplate = {
"username": user["username"],
"id": user["id"],
"created": user["created"]
"created": user["created"],
"storageused": get_space(user["id"]),
"storagemax": int(MAX_STORAGE)
}
return datatemplate
@ -254,6 +266,9 @@ def apieditnote():
note = get_note(noteId)
if get_space(user["id"]) + len(content.encode("utf-8")) > int(MAX_STORAGE):
return {}, 418
if (note != "error"):
if (user["id"] == note["creator"]):
conn = get_db_connection()

31
removeuser Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/python3
import sqlite3
import sys
print("type n to cancel")
answer = input("delete user, what is user id?")
if (answer == "n"):
sys.exit()
def get_db_connection():
conn = sqlite3.connect("database.db")
conn.row_factory = sqlite3.Row
return conn
print("deleting notes")
conn = get_db_connection()
notes = conn.execute("DELETE FROM notes WHERE creator = ?", (int(answer),))
conn.commit()
conn.close()
print("deleting account")
conn = get_db_connection()
conn.execute("DELETE FROM users WHERE id = ?", (int(answer),))
conn.commit()
conn.close()
print("success")

View File

@ -104,6 +104,43 @@ body {
font-family: "Inter", sans-serif;
}
.optionsCoverDiv {
position: fixed;
width: 100%;
height: 100%;
z-index: 2;
background-color: rgba(0, 0, 0, 0.7);
;
}
.optionsDiv {
position: fixed;
left: 12.5%;
top: 12.5%;
width: 75%;
height: 75%;
background-color: white;
padding: 10px;
color: black;
border-radius: 8px;
}
.optionsDiv button {
padding: 10px;
padding-left: 15px;
padding-right: 15px;
color: white;
border: none;
text-decoration: none;
background-color: #157efb;
border-radius: 8px;
}
.optionsDiv .exit {
background-color: #e9e9e9;
color: black;
}
/* Sign up/log in div */
.inoutdiv {
@ -148,6 +185,7 @@ body {
.mainDiv {
text-align: center;
}
.mainDiv a {
padding: 10px;
padding-left: 15px;
@ -157,6 +195,7 @@ body {
background-color: #157efb;
border-radius: 8px;
}
.mainDiv .feature {
width: 80%;
margin-left: 10%;
@ -165,12 +204,15 @@ body {
border-radius: 8px;
font-size: 17px;
}
.mainDiv .green {
background-color: #ebffeb;
}
.mainDiv .yellow {
background-color: #ffffeb;
}
.mainDiv img {
margin: 10px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);

View File

@ -30,6 +30,15 @@ signupButton.addEventListener("click", (event) => {
let username = usernameBox.value
let password = passwordBox.value
if (username == "") {
statusBox.innerText = "username required"
return
}
if (password == "") {
statusBox.innerText = "password required"
return
}
showElements(false)
statusBox.innerText = "welcome back!"

View File

@ -7,10 +7,17 @@ if (localStorage.getItem("DONOTSHARE-password") === null) {
throw new Error();
}
function formatBytes(a, b = 2) { if (!+a) return "0 Bytes"; const c = 0 > b ? 0 : b, d = Math.floor(Math.log(a) / Math.log(1024)); return `${parseFloat((a / Math.pow(1024, d)).toFixed(c))} ${["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"][d]}` }
let secretkey = localStorage.getItem("DONOTSHARE-secretkey")
let password = localStorage.getItem("DONOTSHARE-password")
let usernameBox = document.getElementById("usernameBox")
let optionsCoverDiv = document.getElementById("optionsCoverDiv")
let exitThing = document.getElementById("exitThing")
let storageThing = document.getElementById("storageThing")
let usernameThing = document.getElementById("usernameThing")
let logOutButton = document.getElementById("logOutButton")
let notesBar = document.getElementById("notesBar")
let notesDiv = document.getElementById("notesDiv")
let newNote = document.getElementById("newNote")
@ -85,8 +92,16 @@ fetch("/api/userinfo", {
let responseData = await response.json()
usernameBox.innerText = responseData["username"]
usernameBox.addEventListener("click", (event) => {
optionsCoverDiv.classList.remove("hidden")
usernameThing.innerText = "logged in as " + responseData["username"]
storageThing.innerText = "you've used " + formatBytes(responseData["storageused"]) + " out of " + formatBytes(responseData["storagemax"])
});
logOutButton.addEventListener("click", (event) => {
window.location.href = "/api/logout"
});
exitThing.addEventListener("click", (event) => {
optionsCoverDiv.classList.add("hidden")
});
}
doStuff()
});
@ -139,6 +154,12 @@ function selectNote(nameithink) {
"Content-type": "application/json; charset=UTF-8"
}
})
.then((response) => response)
.then((response) => {
if (response.status == 418) {
alert("you've ran out of storage :3 changes will not be saved until you free up storage!!! owo")
}
})
}
}, waitTime);
});

View File

@ -23,6 +23,17 @@
<div id="notesDiv" class="notesDiv">
</div>
</div>
<div id="optionsCoverDiv" class="optionsCoverDiv hidden">
<div class="optionsDiv">
<button class="exit" id="exitThing">exit</button>
<h3>manage your account</h3>
<p id="usernameThing"></p>
<p id="storageThing"></p>
<button id="logOutButton">log out</button>
</div>
</div>
<textarea id="noteBox" class="noteBox"></textarea>
<script type="text/javascript" src="/static/js/main.js"></script>