Add server backup
This commit is contained in:
@@ -17,7 +17,8 @@
|
|||||||
import MobileBody from './lib/Mobile/MobileBody.svelte';
|
import MobileBody from './lib/Mobile/MobileBody.svelte';
|
||||||
import MobileFooter from './lib/Mobile/MobileFooter.svelte';
|
import MobileFooter from './lib/Mobile/MobileFooter.svelte';
|
||||||
import CustomGUISettingMenu from './lib/Setting/Pages/CustomGUISettingMenu.svelte';
|
import CustomGUISettingMenu from './lib/Setting/Pages/CustomGUISettingMenu.svelte';
|
||||||
import { checkCharOrder } from './ts/globalApi.svelte';
|
import { checkCharOrder } from './ts/globalApi.svelte';
|
||||||
|
import Googli from './lib/UI/Googli.svelte';
|
||||||
|
|
||||||
|
|
||||||
let didFirstSetup: boolean = $derived(DBState.db?.didFirstSetup)
|
let didFirstSetup: boolean = $derived(DBState.db?.didFirstSetup)
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
await importCharacterProcess({
|
await importCharacterProcess({
|
||||||
name: file.name,
|
name: file.name,
|
||||||
data: file
|
data: file
|
||||||
})
|
})
|
||||||
checkCharOrder()
|
checkCharOrder()
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
@@ -51,6 +52,8 @@
|
|||||||
|
|
||||||
<span class="text-sm mt-2 text-textcolor2">{LoadingStatusState.text}</span>
|
<span class="text-sm mt-2 text-textcolor2">{LoadingStatusState.text}</span>
|
||||||
|
|
||||||
|
<Googli className="mt-4" />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{:else if $CustomGUISettingMenuStore}
|
{:else if $CustomGUISettingMenuStore}
|
||||||
<CustomGUISettingMenu />
|
<CustomGUISettingMenu />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import { hubURL } from "src/ts/characterCards";
|
import { hubURL } from "src/ts/characterCards";
|
||||||
import { loadRisuAccountData, saveRisuAccountData } from "src/ts/drive/accounter";
|
import { loadRisuAccountBackup, loadRisuAccountData, saveRisuAccountData } from "src/ts/drive/accounter";
|
||||||
|
|
||||||
import { DBState } from 'src/ts/stores.svelte';
|
import { DBState } from 'src/ts/stores.svelte';
|
||||||
import Check from "src/lib/UI/GUI/CheckInput.svelte";
|
import Check from "src/lib/UI/GUI/CheckInput.svelte";
|
||||||
@@ -69,6 +69,13 @@
|
|||||||
}} className="mt-2">
|
}} className="mt-2">
|
||||||
{language.loadInternalBackup}
|
{language.loadInternalBackup}
|
||||||
</Button>
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<Button
|
||||||
|
onclick={async () => {
|
||||||
|
loadRisuAccountBackup()
|
||||||
|
}} className="mt-2">
|
||||||
|
{language.loadAutoServerBackup}
|
||||||
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
27
src/lib/UI/Googli.svelte
Normal file
27
src/lib/UI/Googli.svelte
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
export let className: string = "";
|
||||||
|
onMount(() => {
|
||||||
|
if(!import.meta.env.VITE_AD_CLIENT){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//@ts-ignore
|
||||||
|
(window.adsbygoogle = window.adsbygoogle || []).push({});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if !import.meta.env.VITE_AD_CLIENT}
|
||||||
|
<div
|
||||||
|
class={className}
|
||||||
|
>
|
||||||
|
<ins
|
||||||
|
class="adsbygoogle"
|
||||||
|
style="display:block"
|
||||||
|
data-ad-client={import.meta.env.VITE_AD_CLIENT}
|
||||||
|
data-ad-slot={import.meta.env.VITE_AD_SLOT}
|
||||||
|
data-ad-format="auto"
|
||||||
|
data-full-width-responsive="true"
|
||||||
|
></ins>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
@@ -29,12 +29,5 @@ export function preLoadCheck(){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Redirect to the main page if the user has not visited the main page
|
|
||||||
if(localStorage.getItem('mainpage') !== 'visited') {
|
|
||||||
localStorage.setItem('mainpage', 'visited');
|
|
||||||
location.replace('https://risuai.net');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import { hubURL } from "../characterCards"
|
import { hubURL } from "../characterCards"
|
||||||
import { getDatabase } from "../storage/database.svelte"
|
import { getDatabase, setDatabase } from "../storage/database.svelte"
|
||||||
import { alertError, alertSelect } from "../alert"
|
import { alertError, alertMd, alertNormal, alertSelect, alertWait } from "../alert"
|
||||||
|
import { AppendableBuffer } from "../globalApi.svelte"
|
||||||
|
import { decodeRisuSave } from "../storage/risuSave"
|
||||||
|
|
||||||
export async function risuLogin() {
|
export async function risuLogin() {
|
||||||
const win = window.open(hubURL + '/hub/login')
|
const win = window.open(hubURL + '/hub/login')
|
||||||
@@ -63,19 +65,72 @@ export async function loadRisuAccountBackup() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if(s.status !== 200){
|
if(s.status !== 200){
|
||||||
alertError(await s.text())
|
alertMd(await s.text())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const backups = await s.json()
|
const backups = await s.json() as string[]
|
||||||
if(!backups.length){
|
if(!backups.length){
|
||||||
alertError("No backups found")
|
alertError("No backups found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const backupIdStr = await alertSelect(backups)
|
const backupIdStr = await alertSelect([...backups.map((v) => {
|
||||||
|
const int = parseInt(v)
|
||||||
|
|
||||||
|
if(!isNaN(int)){
|
||||||
|
const intl = new Intl.DateTimeFormat([
|
||||||
|
navigator.language,
|
||||||
|
'en-US'
|
||||||
|
], {
|
||||||
|
dateStyle: 'short',
|
||||||
|
timeStyle: 'short'
|
||||||
|
}).format(new Date(int))
|
||||||
|
return intl
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}), "Cancel"])
|
||||||
const backupIdNum = parseInt(backupIdStr)
|
const backupIdNum = parseInt(backupIdStr)
|
||||||
|
if(backupIdNum === backups.length){
|
||||||
|
return
|
||||||
|
}
|
||||||
if(isNaN(backupIdNum)){
|
if(isNaN(backupIdNum)){
|
||||||
alertError("Invalid backup id")
|
alertError("Invalid backup id")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const backupId = backups[backupIdNum]
|
const backupId = backups[backupIdNum]
|
||||||
|
|
||||||
|
const backup = await fetch(hubURL + '/hub/backup/get', {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"x-risu-auth": db.account.token,
|
||||||
|
'x-risu-key': backupId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if(backup.status !== 200){
|
||||||
|
alertError(await backup.text())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
const buf = new AppendableBuffer()
|
||||||
|
const reader = backup.body.getReader()
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
const {done, value} = await reader.read()
|
||||||
|
if(done){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
alertWait("Downloading backup: " + buf.buffer.byteLength)
|
||||||
|
buf.append(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
alertWait("Loading backup")
|
||||||
|
|
||||||
|
setDatabase(
|
||||||
|
await decodeRisuSave(buf.buffer)
|
||||||
|
)
|
||||||
|
|
||||||
|
await alertNormal('Loaded backup')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user