Fix remote image urls not showing up in image grids #427
1 changed files with 9 additions and 10 deletions
|
@ -30,22 +30,21 @@ export default class ImageHelper {
|
|||
|
||||
const filePath = path.join(process.env.DATA_DIR!, "cards", card.path);
|
||||
|
||||
const exists = existsSync(filePath) || card.path.startsWith("http://") || card.path.startsWith("https://");
|
||||
|
||||
if (!exists) {
|
||||
AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
let bitmap: Bitmap;
|
||||
|
||||
|
||||
if (card.path.startsWith("http://") || card.path.startsWith("https://")) {
|
||||
if (existsSync(filePath)) {
|
||||
VylpesTester
commented
This could also then be put into an if else chain in the if below This could also then be put into an if else chain in the if below
|
||||
const data = await Jimp.read(filePath);
|
||||
|
||||
bitmap = data.bitmap;
|
||||
} else if (card.path.startsWith("http://") || card.path.startsWith("https://")) {
|
||||
const response = await axios.get(card.path, { responseType: "arraybuffer" });
|
||||
const buffer = Buffer.from(response.data);
|
||||
const data = await Jimp.fromBuffer(buffer);
|
||||
|
||||
bitmap = (await Jimp.fromBuffer(buffer)).bitmap;
|
||||
bitmap = data.bitmap;
|
||||
} else {
|
||||
bitmap = (await Jimp.read(filePath)).bitmap;
|
||||
AppLogger.LogError("ImageHelper/GenerateCardImageGrid", `Failed to load image from path ${card.path}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const imageData = Jimp.fromBitmap(bitmap);
|
||||
|
|
Loading…
Add table
Reference in a new issue
Do we want to instead make the
startsWith
part its own variable? Might be a bit more readable and such IMO