[fix] new backupformating
This commit is contained in:
@@ -60,6 +60,19 @@ export async function alertSelect(msg:string[]){
|
|||||||
return get(alertStore).msg
|
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){
|
export function alertMd(msg:string){
|
||||||
alertStore.set({
|
alertStore.set({
|
||||||
'type': 'markdown',
|
'type': 'markdown',
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { get } from "svelte/store";
|
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 { DataBase, setDatabase, type Database } from "../storage/database";
|
||||||
import { forageStorage, getUnpargeables, isNodeServer, isTauri, openURL } from "../storage/globalApi";
|
import { forageStorage, getUnpargeables, isNodeServer, isTauri, openURL } from "../storage/globalApi";
|
||||||
import { BaseDirectory, exists, readBinaryFile, readDir, writeBinaryFile } from "@tauri-apps/api/fs";
|
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')){
|
if(!key || !key.endsWith('.png')){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const formatedKey = formatKeys(key)
|
const formatedKey = newFormatKeys(key)
|
||||||
if(!fileNames.includes(formatedKey)){
|
if(!fileNames.includes(formatedKey)){
|
||||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readBinaryFile(asset.path))
|
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readBinaryFile(asset.path))
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
|||||||
if(!key.endsWith('.png')){
|
if(!key.endsWith('.png')){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const formatedKey = formatKeys(key)
|
const formatedKey = newFormatKeys(key)
|
||||||
if(!fileNames.includes(formatedKey)){
|
if(!fileNames.includes(formatedKey)){
|
||||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await forageStorage.getItem(key))
|
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}`)
|
localStorage.setItem('risu_lastsaved', `${lastSaved}`)
|
||||||
const requiredImages = (getUnpargeables(db))
|
const requiredImages = (getUnpargeables(db))
|
||||||
let ind = 0;
|
let ind = 0;
|
||||||
|
let errorLogs:string[] = []
|
||||||
for(const images of requiredImages){
|
for(const images of requiredImages){
|
||||||
ind += 1
|
ind += 1
|
||||||
const formatedImage = formatKeys(images)
|
for(let tries=0;tries<3;tries++){
|
||||||
|
const formatedImage = tries === 0 ? newFormatKeys(images) : formatKeys(images)
|
||||||
if(mode === 'sync'){
|
if(mode === 'sync'){
|
||||||
alertStore.set({
|
alertStore.set({
|
||||||
type: "wait",
|
type: "wait",
|
||||||
@@ -401,7 +403,8 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
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
|
db.didFirstSetup = true
|
||||||
const dbData = encodeRisuSave(db, 'compression')
|
const dbData = encodeRisuSave(db, 'compression')
|
||||||
|
|
||||||
|
if(errorLogs.length !== 0){
|
||||||
|
await alertErrorWait(`Errors: ${errorLogs.join('\n')}`)
|
||||||
|
}
|
||||||
|
|
||||||
if(isTauri){
|
if(isTauri){
|
||||||
await writeBinaryFile('database/database.bin', dbData, {dir: BaseDirectory.AppData})
|
await writeBinaryFile('database/database.bin', dbData, {dir: BaseDirectory.AppData})
|
||||||
relaunch()
|
relaunch()
|
||||||
@@ -440,6 +447,12 @@ function formatKeys(name:string) {
|
|||||||
return getBasename(name).replace(/\_/g, '__').replace(/\./g,'_d').replace(/\//,'_s') + '.png'
|
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[]> {
|
async function getFilesInFolder(ACCESS_TOKEN:string, nextPageToken=''): Promise<DriveFile[]> {
|
||||||
const url = `https://www.googleapis.com/drive/v3/files?spaces=appDataFolder&pageSize=300` + nextPageToken;
|
const url = `https://www.googleapis.com/drive/v3/files?spaces=appDataFolder&pageSize=300` + nextPageToken;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user