export notes
This commit is contained in:
parent
c99ac8acd2
commit
145cad27fa
27
main
27
main
|
@ -214,6 +214,33 @@ def apilistnotes():
|
|||
datatemplate.append(notetemplate)
|
||||
|
||||
return datatemplate, 200
|
||||
|
||||
@app.route("/api/exportnotes", methods=("GET", "POST"))
|
||||
def apiexportnotes():
|
||||
if request.method == "POST":
|
||||
data = request.get_json()
|
||||
secretKey = data["secretKey"]
|
||||
|
||||
userCookie = get_session(secretKey)
|
||||
user = get_user(userCookie["id"])
|
||||
|
||||
conn = get_db_connection()
|
||||
notes = conn.execute("SELECT * FROM notes WHERE creator = ? ORDER BY id DESC;", (user["id"],)).fetchall()
|
||||
conn.close()
|
||||
|
||||
datatemplate = []
|
||||
|
||||
for note in notes:
|
||||
notetemplate = {
|
||||
"id": note["id"],
|
||||
"created": note["created"],
|
||||
"edited": note["edited"],
|
||||
"title": note["title"],
|
||||
"content": note["content"]
|
||||
}
|
||||
datatemplate.append(notetemplate)
|
||||
|
||||
return datatemplate, 200
|
||||
|
||||
@app.route("/api/newnote", methods=("GET", "POST"))
|
||||
def apinewnote():
|
||||
|
|
|
@ -188,6 +188,7 @@ body {
|
|||
padding: 10px;
|
||||
color: black;
|
||||
border-radius: 8px;
|
||||
min-width: 338.5px
|
||||
}
|
||||
|
||||
.optionsDiv button {
|
||||
|
|
|
@ -29,6 +29,7 @@ let noteBox = document.getElementById("noteBox")
|
|||
let loadingStuff = document.getElementById("loadingStuff")
|
||||
let burgerDropdown = document.getElementById("burgerDropdown")
|
||||
let burgerButton = document.getElementById("burgerButton")
|
||||
let exportNotesButton = document.getElementById("exportNotesButton")
|
||||
|
||||
for (let i = 0; i < 40; i++) {
|
||||
notesDiv.appendChild(loadingStuff.cloneNode())
|
||||
|
@ -305,4 +306,54 @@ burgerButton.addEventListener("click", (event) => {
|
|||
|
||||
burgerDropdown.style.left = String(event.clientX) + "px"
|
||||
burgerDropdown.style.top = String(event.clientY) + "px"
|
||||
});
|
||||
function downloadObjectAsJson(exportObj, exportName) {
|
||||
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
|
||||
var downloadAnchorNode = document.createElement("a");
|
||||
downloadAnchorNode.setAttribute("href", dataStr);
|
||||
downloadAnchorNode.setAttribute("download", exportName + ".json");
|
||||
document.body.appendChild(downloadAnchorNode);
|
||||
downloadAnchorNode.click();
|
||||
downloadAnchorNode.remove();
|
||||
}
|
||||
|
||||
function exportNotes() {
|
||||
let noteExport = []
|
||||
fetch("/api/exportnotes", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
secretKey: secretkey
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
.then((response) => response)
|
||||
.then((response) => {
|
||||
async function doStuff() {
|
||||
let responseData = await response.json()
|
||||
for (let i in responseData) {
|
||||
let bytes = CryptoJS.AES.decrypt(responseData[i]["title"], password);
|
||||
let originalTitle = bytes.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
responseData[i]["title"] = originalTitle
|
||||
|
||||
let bytesd = CryptoJS.AES.decrypt(responseData[i]["content"], password);
|
||||
let originalContent = bytesd.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
responseData[i]["content"] = originalContent
|
||||
}
|
||||
let jsonString = JSON.parse(JSON.stringify(responseData))
|
||||
console.log(jsonString)
|
||||
|
||||
downloadObjectAsJson(jsonString, "data")
|
||||
}
|
||||
doStuff()
|
||||
})
|
||||
}
|
||||
|
||||
exportNotesButton.addEventListener("click", (event) => {
|
||||
exportNotesButton.innerText = "exporting.."
|
||||
exportNotes()
|
||||
exportNotesButton.innerText = "export notes"
|
||||
});
|
|
@ -39,6 +39,7 @@
|
|||
<p id="storageThing"></p>
|
||||
<button id="logOutButton">log out</button>
|
||||
<button id="deleteMyAccountButton">delete my account</button>
|
||||
<button id="exportNotesButton">export notes</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue