-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
(function functionToExecute() { | ||
// Open the database connection. | ||
const open = indexedDB.open("/userfs"); | ||
|
||
open.onupgradeneeded = function () { | ||
// Define the database schema if necessary. | ||
const db = open.result; | ||
const store = db.createObjectStore("/userfs"); | ||
console.log("------------> Upgraded userfs?"); | ||
}; | ||
|
||
open.onsuccess = function () { | ||
const db = open.result; | ||
const key = "/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg"; | ||
|
||
// Write file to DB | ||
// var tx = db.transaction('files', 'readwrite'); | ||
// var store = tx.objectStore('files'); | ||
// store.put(null, "test"); | ||
|
||
// Later, read file back out of DB | ||
// let tx2: IDBTransaction | undefined; | ||
let tx2; | ||
try { | ||
tx2 = db.transaction("FILE_DATA", "readonly"); | ||
} catch (DOMException) { | ||
console.error("Failed to get user data from indexedDB"); | ||
return; | ||
} | ||
if (!tx2) { | ||
return; | ||
} | ||
const store2 = tx2.objectStore("FILE_DATA"); | ||
const request = store2.get(key); | ||
|
||
request.onsuccess = function (e) { | ||
// Got the file! | ||
const file = request.result; | ||
|
||
if (file == null) { | ||
alert("You haven't generated any results yet."); | ||
console.log("File is null"); | ||
return; | ||
} else { | ||
console.log("Is int8array: " + (file.contents instanceof Int8Array)); | ||
} | ||
|
||
const blob = new Blob([file.contents], { | ||
type: "text/plain;charset=utf-8;", | ||
}); | ||
return blob; | ||
}; | ||
}; | ||
})(); | ||
|
||
export const USER_CONFIG_KEY = | ||
"/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg"; | ||
|
||
export function getGodotFile(res: unknown, file: string = USER_CONFIG_KEY) { | ||
// Open the database connection. | ||
const open = indexedDB.open("/userfs"); | ||
|
||
open.onsuccess = function () { | ||
const db = open.result; | ||
const key = file; | ||
|
||
// Later, read file back out of DB | ||
let tx: IDBTransaction | undefined; | ||
try { | ||
tx = db.transaction("FILE_DATA", "readonly"); | ||
} catch (DOMException) { | ||
console.error("Failed to get user data from indexedDB"); | ||
return; | ||
} | ||
if (!tx) { | ||
return; | ||
} | ||
const store2 = tx.objectStore("FILE_DATA"); | ||
const request = store2.get(key); | ||
|
||
request.onsuccess = function (): Blob { | ||
// Got the file! | ||
const file = request.result; | ||
|
||
if (file == null) { | ||
throw new Error("File not found"); | ||
} else { | ||
console.log("Is int8array: " + (file.contents instanceof Int8Array)); | ||
} | ||
|
||
const blob = new Blob([file.contents], { | ||
type: "text/plain;charset=utf-8;", | ||
}); | ||
res.blob = blob; | ||
return blob; | ||
}; | ||
return request; | ||
}; | ||
return open; | ||
} |