[fix] new backupformating

This commit is contained in:
kwaroran
2023-11-17 22:41:20 +09:00
parent 79875661c5
commit 929ed557d2
2 changed files with 60 additions and 34 deletions

View File

@@ -60,6 +60,19 @@ export async function alertSelect(msg:string[]){
return get(alertStore).msg
}
export async function alertErrorWait(msg:string){
alertStore.set({
'type': 'wait2',
'msg': msg
})
while(true){
if (get(alertStore).type === 'none'){
break
}
await sleep(10)
}
}
export function alertMd(msg:string){
alertStore.set({
'type': 'markdown',

View File

@@ -1,5 +1,5 @@
import { get } from "svelte/store";
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
import { alertError, alertErrorWait, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
import { DataBase, setDatabase, type Database } from "../storage/database";
import { forageStorage, getUnpargeables, isNodeServer, isTauri, openURL } from "../storage/globalApi";
import { BaseDirectory, exists, readBinaryFile, readDir, writeBinaryFile } from "@tauri-apps/api/fs";
@@ -221,7 +221,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
if(!key || !key.endsWith('.png')){
continue
}
const formatedKey = formatKeys(key)
const formatedKey = newFormatKeys(key)
if(!fileNames.includes(formatedKey)){
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readBinaryFile(asset.path))
}
@@ -239,7 +239,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
if(!key.endsWith('.png')){
continue
}
const formatedKey = formatKeys(key)
const formatedKey = newFormatKeys(key)
if(!fileNames.includes(formatedKey)){
await createFileInFolder(ACCESS_TOKEN, formatedKey, await forageStorage.getItem(key))
}
@@ -366,9 +366,11 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
localStorage.setItem('risu_lastsaved', `${lastSaved}`)
const requiredImages = (getUnpargeables(db))
let ind = 0;
let errorLogs:string[] = []
for(const images of requiredImages){
ind += 1
const formatedImage = formatKeys(images)
for(let tries=0;tries<3;tries++){
const formatedImage = tries === 0 ? newFormatKeys(images) : formatKeys(images)
if(mode === 'sync'){
alertStore.set({
type: "wait",
@@ -401,7 +403,8 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
}
}
else{
throw `cannot find file in drive: ${formatedImage}`
errorLogs.push(`Missing ${images}, skipping...`)
}
}
}
}
@@ -409,6 +412,10 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
db.didFirstSetup = true
const dbData = encodeRisuSave(db, 'compression')
if(errorLogs.length !== 0){
await alertErrorWait(`Errors: ${errorLogs.join('\n')}`)
}
if(isTauri){
await writeBinaryFile('database/database.bin', dbData, {dir: BaseDirectory.AppData})
relaunch()
@@ -440,6 +447,12 @@ function formatKeys(name:string) {
return getBasename(name).replace(/\_/g, '__').replace(/\./g,'_d').replace(/\//,'_s') + '.png'
}
function newFormatKeys(name:string) {
let n = getBasename(name)
const bf = Buffer.from(n).toString('hex')
return n + '.bin'
}
async function getFilesInFolder(ACCESS_TOKEN:string, nextPageToken=''): Promise<DriveFile[]> {
const url = `https://www.googleapis.com/drive/v3/files?spaces=appDataFolder&pageSize=300` + nextPageToken;