conjure-os/frontend/src/utils/image-manager.ts
2025-06-30 21:32:08 -04:00

30 lines
998 B
TypeScript

import { LoadImage } from "../../wailsjs/go/main/App";
export class ImageManager {
static Dictionary: {[key: string]: string} = {}
public static async getImage(gameId: string, src: string): Promise<string> {
const id = gameId + "\\" + src;
console.log(gameId, src, id)
if (this.Dictionary[id])
return this.Dictionary[id]
const fileBlob = await LoadImage(gameId, src);
console.log(fileBlob)
const byteCharacters = atob(fileBlob.Data as any as string);
const byteNumbers = Array.from(byteCharacters).map(c => c.charCodeAt(0));
console.log(byteCharacters, byteNumbers)
const bytes = new Uint8Array(byteNumbers);
console.log(bytes)
const blob = new Blob([bytes], {type: fileBlob.MimeType });
console.log(blob)
const url = URL.createObjectURL(blob);
console.log(url)
this.Dictionary[id] = url
console.log(this.Dictionary)
return url;
}
}