2019-09-12 09:11:32 +00:00
|
|
|
import { Database } from "./database";
|
|
|
|
|
|
|
|
const imgBaseURL = "https://mcg.zyg.ovh/images/cards/";
|
2019-09-20 10:49:15 +00:00
|
|
|
let imageSource: "local" | "remote" = "remote";
|
2019-09-12 09:11:32 +00:00
|
|
|
|
2019-09-20 10:49:15 +00:00
|
|
|
export function remoteImageURL(cardid: string): string {
|
2019-09-12 09:11:32 +00:00
|
|
|
return `${imgBaseURL}${cardid}.webp`;
|
|
|
|
}
|
|
|
|
|
2019-09-20 10:49:15 +00:00
|
|
|
export async function cardImageURL(cardid: string): Promise<string> {
|
|
|
|
if (!Database) {
|
|
|
|
return remoteImageURL(cardid);
|
|
|
|
}
|
|
|
|
switch (cardImageSource()) {
|
|
|
|
case "local":
|
|
|
|
const card = await Database.images.get(`${cardid}.webp`);
|
|
|
|
if (!card) {
|
|
|
|
return remoteImageURL(cardid);
|
|
|
|
}
|
|
|
|
return URL.createObjectURL(card.image);
|
|
|
|
//TODO
|
|
|
|
case "remote":
|
|
|
|
return remoteImageURL(cardid);
|
|
|
|
}
|
2019-09-12 09:11:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 10:49:15 +00:00
|
|
|
export function cardImageSource() {
|
|
|
|
return imageSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function refreshCardSource() {
|
|
|
|
if (!Database) {
|
2019-09-12 09:11:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-20 10:49:15 +00:00
|
|
|
const count = await Database.images.count();
|
|
|
|
imageSource = count > 1900 ? "local" : "remote";
|
2019-09-12 09:11:32 +00:00
|
|
|
}
|