mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-09 03:47:26 +08:00
feat: add url support (wip)
This commit is contained in:
@@ -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", "");
|
||||
}
|
||||
Reference in New Issue
Block a user