Skip to content

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed May 3, 2024
1 parent 7ca4503 commit 9994f68
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import i18next from 'i18next'
import localforage from 'localforage'
import { DOMCacheGetOrSet } from './Cache/DOM'
import { QuarkHandler } from './Quark'
import { player } from './Synergism'
Expand Down Expand Up @@ -119,10 +120,23 @@ export async function handleLogin () {
`.trim()

const logoutElement = document.createElement('button')
const cloudSaveElement = document.createElement('button')
// const loadCloudSaveElement = document.createElement('button')

logoutElement.addEventListener('click', logout, { once: true })
logoutElement.style.cssText = 'border: 2px solid #5865F2; height: 25px; width: 150px;'
logoutElement.textContent = 'Log Out'

if (personalBonus > 1) {
cloudSaveElement.addEventListener('click', saveToCloud)
cloudSaveElement.style.cssText = 'border: 2px solid #5865F2; height: 75px; width: 150px;'
cloudSaveElement.textContent = 'Save to Cloud ☁'
}

// loadCloudSaveElement.addEventListener('click', loadFromCloud)
// loadCloudSaveElement.style.cssText = 'border: 2px solid #5865F2; height: 75px; width: 150px;'
// loadCloudSaveElement.textContent = 'Load from Cloud ☽'

subtabElement.appendChild(logoutElement)
} else {
// User is not logged in
Expand Down Expand Up @@ -152,3 +166,27 @@ async function logout () {

location.reload()
}

async function saveToCloud () {
const save = (await localforage.getItem<Blob>('Synergysave2')
.then(b => b?.text())
.catch(() => null)) ?? localStorage.getItem('Synergysave2')

if (typeof save !== 'string') {
console.log('Yeah, no save here.')
return
}

const body = new FormData()
body.set('savefile', new File([save], 'file.txt'), 'file.txt')

const response = await fetch('https://synergism.cc/api/v1/saves/upload', {
method: 'POST',
body
})

if (!response.ok) {
await Alert(`Received an error: ${await response.text()}`)
return
}
}

0 comments on commit 9994f68

Please sign in to comment.