35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { LoadImage } from "../../wailsjs/go/main/App";
|
|
|
|
export class ImageService {
|
|
|
|
static Dictionary: {[key: string]: string} = {}
|
|
|
|
public static async getImage(gameId: string, src: string): Promise<string> {
|
|
|
|
if (!src || src.startsWith("http")) {
|
|
return src;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
} |