@@ -86,6 +98,11 @@
msg: document.querySelector('#alert-input')?.value
})
}}>OK
+ {:else if $alertStore.type === 'login'}
+
+
+
{:else if $alertStore.type === 'selectChar'}
{#each $DataBase.characters as char, i}
diff --git a/src/ts/alert.ts b/src/ts/alert.ts
index d29e3427..07b24d75 100644
--- a/src/ts/alert.ts
+++ b/src/ts/alert.ts
@@ -3,7 +3,7 @@ import { sleep } from "./util"
import { language } from "../lang"
interface alertData{
- type: 'error'| 'normal'|'none'|'ask'|'wait'|'selectChar'|'input'|'toast'|'wait2'|'markdown'|'select'
+ type: 'error'| 'normal'|'none'|'ask'|'wait'|'selectChar'|'input'|'toast'|'wait2'|'markdown'|'select'|'login'
msg: string
}
@@ -29,6 +29,21 @@ export function alertNormal(msg:string){
})
}
+export async function alertLogin(){
+ alertStore.set({
+ 'type': 'login',
+ 'msg': 'login'
+ })
+ while(true){
+ if (get(alertStore).type === 'none'){
+ break
+ }
+ await sleep(10)
+ }
+
+ return get(alertStore).msg
+}
+
export async function alertSelect(msg:string[]){
alertStore.set({
'type': 'select',
diff --git a/src/ts/storage/accountStorage.ts b/src/ts/storage/accountStorage.ts
index 1142c050..7cb0abb8 100644
--- a/src/ts/storage/accountStorage.ts
+++ b/src/ts/storage/accountStorage.ts
@@ -2,42 +2,53 @@ import { get } from "svelte/store"
import { DataBase } from "./database"
import { hubURL } from "../characterCards"
import localforage from "localforage"
+import { alertLogin } from "../alert"
export class AccountStorage{
auth:string
usingSync:boolean
async setItem(key:string, value:Uint8Array) {
- await this.checkAuth()
- const da = await fetch(hubURL + '/api/account/write', {
- method: "POST",
- body: value,
- headers: {
- 'content-type': 'application/json',
- 'x-risu-key': key,
- 'x-risu-auth': this.auth ?? sessionStorage.getItem("fallbackRisuToken")
- }
- })
+ this.checkAuth()
+ let da:Response
+ while((!da) || da.status === 403){
+ da = await fetch(hubURL + '/api/account/write', {
+ method: "POST",
+ body: value,
+ headers: {
+ 'content-type': 'application/json',
+ 'x-risu-key': key,
+ 'x-risu-auth': this.auth
+ }
+ })
+ localStorage.setItem("fallbackRisuToken",await alertLogin())
+ this.checkAuth()
+ }
if(da.status < 200 || da.status >= 300){
throw await da.text()
}
return await da.text()
}
async getItem(key:string):Promise {
- await this.checkAuth()
+ this.checkAuth()
if(key.startsWith('assets/')){
const k:ArrayBuffer = await localforage.getItem(key)
if(k){
return Buffer.from(k)
}
}
- const da = await fetch(hubURL + '/api/account/read', {
- method: "GET",
- headers: {
- 'x-risu-key': key,
- 'x-risu-auth': this.auth ?? sessionStorage.getItem("fallbackRisuToken")
- }
- })
+ let da:Response
+ while((!da) || da.status === 403){
+ da = await fetch(hubURL + '/api/account/read', {
+ method: "GET",
+ headers: {
+ 'x-risu-key': key,
+ 'x-risu-auth': this.auth
+ }
+ })
+ localStorage.setItem("fallbackRisuToken",await alertLogin())
+ this.checkAuth()
+ }
if(da.status < 200 || da.status >= 300){
throw await da.text()
}
@@ -57,16 +68,12 @@ export class AccountStorage{
throw "Error: You remove data in account. report this to dev if you found this."
}
- private async checkAuth(){
+ private checkAuth(){
const db = get(DataBase)
this.auth = db?.account?.token
if(!this.auth){
- db.account = {
- id: "",
- token: sessionStorage.getItem("fallbackRisuToken"),
- useSync: true,
- data: {}
- }
+ db.account = JSON.parse(localStorage.getItem("fallbackRisuToken"))
+ this.auth = db?.account?.token
}
}
diff --git a/src/ts/storage/autoStorage.ts b/src/ts/storage/autoStorage.ts
index 722cfcc5..f27e4e23 100644
--- a/src/ts/storage/autoStorage.ts
+++ b/src/ts/storage/autoStorage.ts
@@ -38,6 +38,9 @@ export class AutoStorage{
async checkAccountSync(){
let db = get(DataBase)
+ if(this.isAccount){
+ return true
+ }
if(db.account?.useSync && (localStorage.getItem('accountst') !== 'able')){
getUnpargeables(db)
console.log("migrating")
@@ -68,11 +71,13 @@ export class AutoStorage{
})
localStorage.setItem('accountst', 'able')
- sessionStorage.setItem('fallbackRisuToken',db.account?.token)
+ localStorage.setItem('fallbackRisuToken',JSON.stringify(db.account))
+ this.isAccount = true
return true
}
else if(localStorage.getItem('accountst') === 'able'){
this.realStorage = new AccountStorage()
+ this.isAccount = true
}
return false
}
@@ -81,6 +86,7 @@ export class AutoStorage{
if(!this.realStorage){
if(localStorage.getItem('accountst') === 'able'){
this.realStorage = new AccountStorage()
+ this.isAccount = true
return
}
if(isNodeServer){
diff --git a/src/ts/storage/globalApi.ts b/src/ts/storage/globalApi.ts
index d68567e6..d3370732 100644
--- a/src/ts/storage/globalApi.ts
+++ b/src/ts/storage/globalApi.ts
@@ -86,6 +86,10 @@ export async function getFileSrc(loc:string) {
return convertFileSrc(loc)
}
try {
+
+ if(forageStorage.isAccount){
+ return hubURL + `/rs/` + loc
+ }
if(usingSw){
const encoded = Buffer.from(loc,'utf-8').toString('hex')
let ind = fileCache.origin.indexOf(loc)