[feat] data sync first setup message

This commit is contained in:
kwaroran
2023-06-12 12:31:39 +09:00
parent 2de284f4e9
commit 5f93b88cca

View File

@@ -130,8 +130,9 @@ export async function syncDrive() {
maindb.account.data = await s.json() maindb.account.data = await s.json()
} }
const ACCESS_TOKEN = maindb.account.data.access_token const ACCESS_TOKEN = maindb.account.data.access_token
await loadDrive(ACCESS_TOKEN, 'sync') const d = await loadDrive(ACCESS_TOKEN, 'sync')
if(!isEqual(maindb, BackupDb)){ const hadNoSync = d === 'noSync'
if((!isEqual(maindb, BackupDb)) || hadNoSync){
BackupDb = cloneDeep(maindb) BackupDb = cloneDeep(maindb)
const files:DriveFile[] = await getFilesInFolder(ACCESS_TOKEN) const files:DriveFile[] = await getFilesInFolder(ACCESS_TOKEN)
const fileNames = files.map((d) => { const fileNames = files.map((d) => {
@@ -142,6 +143,12 @@ export async function syncDrive() {
let i = 0; let i = 0;
for(let asset of assets){ for(let asset of assets){
i += 1; i += 1;
if(hadNoSync){
alertStore.set({
type: "wait",
msg: `Uploading Sync Files... (${i} / ${assets.length})`
})
}
const key = asset.name const key = asset.name
if(!key || !key.endsWith('.png')){ if(!key || !key.endsWith('.png')){
continue continue
@@ -156,6 +163,12 @@ export async function syncDrive() {
const keys = await forageStorage.keys() const keys = await forageStorage.keys()
for(let i=0;i<keys.length;i++){ for(let i=0;i<keys.length;i++){
if(hadNoSync){
alertStore.set({
type: "wait",
msg: `Uploading Sync Files... (${i} / ${keys.length})`
})
}
const key = keys[i] const key = keys[i]
if(!key.endsWith('.png')){ if(!key.endsWith('.png')){
continue continue
@@ -170,6 +183,7 @@ export async function syncDrive() {
lastSaved = Math.floor(Date.now() / 1000) lastSaved = Math.floor(Date.now() / 1000)
localStorage.setItem('risu_lastsaved', `${lastSaved}`) localStorage.setItem('risu_lastsaved', `${lastSaved}`)
await createFileInFolder(ACCESS_TOKEN, `${lastSaved}-database.risudat2`, Buffer.from(dbjson, 'utf-8')) await createFileInFolder(ACCESS_TOKEN, `${lastSaved}-database.risudat2`, Buffer.from(dbjson, 'utf-8'))
alertNormal("First Setup Success")
} }
} }
await sleep(3000) await sleep(3000)
@@ -249,7 +263,7 @@ type DriveFile = {
id: string id: string
} }
async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync') { async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<void|"noSync"> {
if(mode === 'backup'){ if(mode === 'backup'){
alertStore.set({ alertStore.set({
type: "wait", type: "wait",
@@ -278,6 +292,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync') {
let dbs:[DriveFile,number][] = [] let dbs:[DriveFile,number][] = []
let noSyncData = true
if(mode === 'backup'){ if(mode === 'backup'){
for(const f of files){ for(const f of files){
@@ -302,9 +317,12 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync') {
if(isNaN(tm)){ if(isNaN(tm)){
continue continue
} }
else if(tm > lastSaved){ else{
if(tm > lastSaved){
dbs.push([f,tm]) dbs.push([f,tm])
} }
noSyncData = false
}
} }
} }
dbs.sort((a,b) => { dbs.sort((a,b) => {
@@ -312,6 +330,10 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync') {
}) })
} }
if(noSyncData && mode === 'sync'){
return 'noSync'
}
if(dbs.length !== 0){ if(dbs.length !== 0){
if(mode === 'sync'){ if(mode === 'sync'){
alertStore.set({ alertStore.set({