burger
This commit is contained in:
parent
497b25915a
commit
37dfef84f5
|
@ -2,3 +2,4 @@
|
||||||
HOST = 0.0.0.0
|
HOST = 0.0.0.0
|
||||||
PORT = 8080
|
PORT = 8080
|
||||||
SECRET_KEY = placeholder
|
SECRET_KEY = placeholder
|
||||||
|
MAX_STORAGE = 25000000
|
17
main
17
main
|
@ -14,6 +14,7 @@ config.read("config.ini")
|
||||||
HOST = config["config"]["HOST"]
|
HOST = config["config"]["HOST"]
|
||||||
PORT = config["config"]["PORT"]
|
PORT = config["config"]["PORT"]
|
||||||
SECRET_KEY = config["config"]["SECRET_KEY"]
|
SECRET_KEY = config["config"]["SECRET_KEY"]
|
||||||
|
MAX_STORAGE = config["config"]["MAX_STORAGE"]
|
||||||
|
|
||||||
if SECRET_KEY == "placeholder":
|
if SECRET_KEY == "placeholder":
|
||||||
print("[WARNING] Secret key not set")
|
print("[WARNING] Secret key not set")
|
||||||
|
@ -46,6 +47,15 @@ def get_note(id):
|
||||||
return "error"
|
return "error"
|
||||||
return post
|
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):
|
def get_session(id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
post = conn.execute("SELECT * FROM sessions WHERE session = ?",
|
post = conn.execute("SELECT * FROM sessions WHERE session = ?",
|
||||||
|
@ -171,7 +181,9 @@ def apiuserinfo():
|
||||||
datatemplate = {
|
datatemplate = {
|
||||||
"username": user["username"],
|
"username": user["username"],
|
||||||
"id": user["id"],
|
"id": user["id"],
|
||||||
"created": user["created"]
|
"created": user["created"],
|
||||||
|
"storageused": get_space(user["id"]),
|
||||||
|
"storagemax": int(MAX_STORAGE)
|
||||||
}
|
}
|
||||||
return datatemplate
|
return datatemplate
|
||||||
|
|
||||||
|
@ -254,6 +266,9 @@ def apieditnote():
|
||||||
|
|
||||||
note = get_note(noteId)
|
note = get_note(noteId)
|
||||||
|
|
||||||
|
if get_space(user["id"]) + len(content.encode("utf-8")) > int(MAX_STORAGE):
|
||||||
|
return {}, 418
|
||||||
|
|
||||||
if (note != "error"):
|
if (note != "error"):
|
||||||
if (user["id"] == note["creator"]):
|
if (user["id"] == note["creator"]):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
|
|
|
@ -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")
|
|
@ -104,6 +104,43 @@ body {
|
||||||
font-family: "Inter", sans-serif;
|
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 */
|
/* Sign up/log in div */
|
||||||
|
|
||||||
.inoutdiv {
|
.inoutdiv {
|
||||||
|
@ -148,6 +185,7 @@ body {
|
||||||
.mainDiv {
|
.mainDiv {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainDiv a {
|
.mainDiv a {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
|
@ -157,6 +195,7 @@ body {
|
||||||
background-color: #157efb;
|
background-color: #157efb;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainDiv .feature {
|
.mainDiv .feature {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
margin-left: 10%;
|
margin-left: 10%;
|
||||||
|
@ -165,12 +204,15 @@ body {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainDiv .green {
|
.mainDiv .green {
|
||||||
background-color: #ebffeb;
|
background-color: #ebffeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainDiv .yellow {
|
.mainDiv .yellow {
|
||||||
background-color: #ffffeb;
|
background-color: #ffffeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mainDiv img {
|
.mainDiv img {
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
|
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
|
||||||
|
|
|
@ -30,6 +30,15 @@ signupButton.addEventListener("click", (event) => {
|
||||||
let username = usernameBox.value
|
let username = usernameBox.value
|
||||||
let password = passwordBox.value
|
let password = passwordBox.value
|
||||||
|
|
||||||
|
if (username == "") {
|
||||||
|
statusBox.innerText = "username required"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (password == "") {
|
||||||
|
statusBox.innerText = "password required"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
showElements(false)
|
showElements(false)
|
||||||
statusBox.innerText = "welcome back!"
|
statusBox.innerText = "welcome back!"
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,17 @@ if (localStorage.getItem("DONOTSHARE-password") === null) {
|
||||||
throw new Error();
|
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 secretkey = localStorage.getItem("DONOTSHARE-secretkey")
|
||||||
let password = localStorage.getItem("DONOTSHARE-password")
|
let password = localStorage.getItem("DONOTSHARE-password")
|
||||||
|
|
||||||
let usernameBox = document.getElementById("usernameBox")
|
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 notesBar = document.getElementById("notesBar")
|
||||||
let notesDiv = document.getElementById("notesDiv")
|
let notesDiv = document.getElementById("notesDiv")
|
||||||
let newNote = document.getElementById("newNote")
|
let newNote = document.getElementById("newNote")
|
||||||
|
@ -85,8 +92,16 @@ fetch("/api/userinfo", {
|
||||||
let responseData = await response.json()
|
let responseData = await response.json()
|
||||||
usernameBox.innerText = responseData["username"]
|
usernameBox.innerText = responseData["username"]
|
||||||
usernameBox.addEventListener("click", (event) => {
|
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"
|
window.location.href = "/api/logout"
|
||||||
});
|
});
|
||||||
|
exitThing.addEventListener("click", (event) => {
|
||||||
|
optionsCoverDiv.classList.add("hidden")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
doStuff()
|
doStuff()
|
||||||
});
|
});
|
||||||
|
@ -139,6 +154,12 @@ function selectNote(nameithink) {
|
||||||
"Content-type": "application/json; charset=UTF-8"
|
"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);
|
}, waitTime);
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,6 +23,17 @@
|
||||||
<div id="notesDiv" class="notesDiv">
|
<div id="notesDiv" class="notesDiv">
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<textarea id="noteBox" class="noteBox"></textarea>
|
||||||
|
|
||||||
<script type="text/javascript" src="/static/js/main.js"></script>
|
<script type="text/javascript" src="/static/js/main.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue