feat: add url support (wip)

This commit is contained in:
Raymond
2025-01-04 18:00:08 -05:00
parent f68bd54ccd
commit 82a0473287
3 changed files with 61 additions and 16 deletions

View File

@@ -1,3 +1,5 @@
import useLocalStorage from "../hooks/useLocalStorage.svelte";
export default class DDSCache {
constructor(db: IDBDatabase | undefined) {
this.db = db;
@@ -43,7 +45,13 @@ export default class DDSCache {
* @param path Image path
*/
getFromDatabase(path: string): Promise<Blob | null> {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
if (this.userboxURL.value) {
let targetPath = path.replaceAll(":", "/");
let response = await fetch(`${this.userboxURL.value}/${targetPath}.dds`).then(b => b.blob()).catch(reject);
if (response)
return resolve(response);
};
if (!this.db)
return resolve(null);
let transaction = this.db.transaction(["dds"], "readonly");
@@ -61,4 +69,5 @@ export default class DDSCache {
private urlCache: {scale: number, path: string, url: string}[] = [];
private db: IDBDatabase | undefined;
private userboxURL = useLocalStorage("userboxURL", "");
}