[feat] data sync

This commit is contained in:
kwaroran
2023-06-12 12:27:01 +09:00
parent 49a01a0950
commit 2de284f4e9
7 changed files with 296 additions and 44 deletions

View File

@@ -1,3 +1,52 @@
async function loginWithGoogle() {
import { get } from "svelte/store"
import { hubURL } from "../characterCards"
import { DataBase } from "../storage/database"
import { alertError } from "../alert"
export async function risuLogin() {
const win = window.open(hubURL + '/hub/login')
window.addEventListener("message", (ev) => {
console.log(ev)
const data = JSON.parse(ev.data)
console.log(data)
win.close()
})
}
export async function saveRisuAccountData() {
const db = get(DataBase)
if(!db.account){
alertError("Not logged in error")
return
}
const s = await fetch(hubURL + '/hub/account/save', {
method: "POST",
body: JSON.stringify({
token: db.account.token,
save: db.account.data
})
})
if(s.status !== 200){
alertError(await s.text())
return
}
}
export async function loadRisuAccountData() {
const db = get(DataBase)
if(!db.account){
alertError("Not logged in error")
return
}
const s = await fetch(hubURL + '/hub/account/load', {
method: "POST",
body: JSON.stringify({
token: db.account.token
})
})
if(s.status !== 200){
alertError(await s.text())
return
}
db.account.data = await s.json()
}