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", }); }