summaryrefslogtreecommitdiff
path: root/app/public/api.js
diff options
context:
space:
mode:
authorAlexis Hovorka <[email protected]>2024-07-27 19:43:38 -0600
committerAlexis Hovorka <[email protected]>2024-07-27 19:43:38 -0600
commit4702402484a773c0eccf7415d0318e367fb996e1 (patch)
tree54f4857f5664b7f40815c580493bf08adc4dbe88 /app/public/api.js
parentcaa495340aef5b765bed193da51cd4bf48a4d570 (diff)
[refactor] Try out some client-side UI librariesHEADmain
Diffstat (limited to 'app/public/api.js')
-rw-r--r--app/public/api.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/app/public/api.js b/app/public/api.js
new file mode 100644
index 0000000..6321909
--- /dev/null
+++ b/app/public/api.js
@@ -0,0 +1,91 @@
+export async function getNote(id) {
+ const res = await fetch(`${id}`);
+ const note = await res.json();
+ //console.log(note);
+ return note;
+}
+
+export async function getList() {
+ const res = await fetch("/list");
+ const list = await res.json();
+ //console.log(list);
+
+ return Promise.all(list.map(id => getNote(id)));
+}
+
+export async function saveNote(id, content) {
+ const res = await fetch("/"+id, {
+ method: "POST",
+ body: JSON.stringify({id, content}),
+ });
+
+ const note = await res.json();
+ //console.log(note);
+}
+
+export async function newNote() {
+ const res = await fetch("/new", {
+ method: "POST",
+ });
+
+ const note = await res.json();
+ //console.log(note);
+ return note;
+}
+
+export async function getUserData() {
+ const res = await fetch(`/user`);
+ const user = await res.json();
+ //console.log(user);
+ return user;
+}
+
+export async function getUserSessions() {
+ const res = await fetch(`/session-list`);
+ const sessions = await res.json();
+ //console.log(sessions);
+ return sessions;
+}
+
+export async function signIn({username, password, keepSession}) {
+ const res = await fetch("/sign-in", {
+ method: "POST",
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({username, password, keepSession})
+ });
+
+ if (res.ok) return res.json();
+ return {code: res.status, error: res.statusText}; // TODO
+}
+
+export async function changePassword({username, password, newPassword, keepSession}) {
+ const res = await fetch("/change-password", {
+ method: "POST",
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({username, password, newPassword, keepSession})
+ });
+
+ return res.json();
+}
+
+export async function changeUsername({newUsername, password}) {
+ const res = await fetch("/change-username", {
+ method: "POST",
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({newUsername, password})
+ });
+
+ return res.json();
+}
+
+export async function signOut() {
+ const res = await fetch("/sign-out", {
+ method: "POST",
+ });
+}
+
+export async function signOutEverywhere() {
+ const res = await fetch("/deauth-all", {
+ method: "POST",
+ });
+}