Try initializing FileSystem now
- vdisk finished - vdiskmanager finished - devices can properly initialize and hold aswell as retireve data - added mock synchronous store classes for testing
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
/* import { MD5 } from "./hash";
|
||||
|
||||
//INDEXED DB IS SO FUCKING DOGSHIT ITS INSANE
|
||||
|
||||
//TODO: load IDB db name from config;
|
||||
|
||||
export async function initializeIDB() {
|
||||
const request = indexedDB.open("cache");
|
||||
request.onerror = e => {
|
||||
throw new Error(`Failed to open the IDB during the init - ${request.error}`);
|
||||
};
|
||||
|
||||
request.onsuccess = e => {
|
||||
const DB = request.result;
|
||||
const STORE = DB.createObjectStore("fs", { autoIncrement: true });
|
||||
|
||||
STORE.createIndex("json", "json");
|
||||
STORE.createIndex("checksum", "checksum");
|
||||
};
|
||||
}
|
||||
|
||||
export async function writeFileSystemCache(cache: string, checksum: string) {
|
||||
if (cache.length === 0 || checksum.length === 0) {
|
||||
throw new Error(`Cache value or the checksum value cannot be empty!`);
|
||||
}
|
||||
|
||||
if (!isChecksumMatching(cache, checksum))
|
||||
throw new Error("The cache value checksum does not match the provided checksum");
|
||||
|
||||
const request = indexedDB.open("cache");
|
||||
request.onerror = e => {
|
||||
throw new Error(`Failed to open the IDB during the init - ${request.error}`);
|
||||
};
|
||||
|
||||
request.onsuccess = e => {
|
||||
const DB = request.result;
|
||||
const T = DB.transaction(["cache"], "readwrite");
|
||||
const STOREFS = T.objectStore("fs");
|
||||
const STORECK = T.objectStore("fs");
|
||||
|
||||
const RFS = STOREFS.add(cache);
|
||||
//const CFS =
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchFileSystemCache(): Promise<{ cache: string; checksum: string }> {
|
||||
const request = indexedDB.open("cache");
|
||||
|
||||
request.onerror = e => {
|
||||
throw new Error(`Failed to open the IDB - ${request.error}`);
|
||||
};
|
||||
|
||||
request.onsuccess = e => {
|
||||
const DB = request.result;
|
||||
const T = DB.transaction(["cache"], "readonly");
|
||||
const STORE = T.objectStore("fs");
|
||||
|
||||
const R = STORE.get("1");
|
||||
|
||||
R.onerror = e => {
|
||||
throw new Error(`Some IDB error - ${R.error}`);
|
||||
};
|
||||
|
||||
R.onsuccess = e => {
|
||||
console.log(R.result.json, R.result.checksum);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function isChecksumMatching(json: string, checksum: string): boolean {
|
||||
const resourceChksm = MD5.hash(json);
|
||||
return resourceChksm === checksum;
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user