Skip to content

Commit dec3cac

Browse files
committed
3D “box” primary color and dimensions now independently set
1 parent a61af33 commit dec3cac

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

backend/db/CachedMongoClient.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -428,26 +428,41 @@ class CachedMongoClient {
428428
let boardGamesCache = await this.mongoClient.find(this.propertyManager.boardGamesCollectionName, {});
429429
if (boardGamesCache) {
430430
for (let boardGame of boardGamesCache) {
431-
if (this.propertyManager.experimentalBoardGameBoxRendering && !("primaryColor" in boardGame)) {
432-
try {
433-
const image = sharp(`${paths.FRONTEND_STATIC_DIRECTORY_PATH}${boardGame.coverArtFilePath}`);
434-
const stats = await image.stats();
435-
const primaryColor = stats.dominant;
436-
437-
const metadata = await image.metadata();
438-
const ratio = metadata.width / metadata.height;
439-
440-
if (boardGame.primaryColor !== primaryColor || boardGame.ratio !== ratio) {
441-
boardGame.primaryColor = primaryColor;
442-
boardGame.ratio = ratio;
443-
try {
444-
await this.upsertBoardGame(boardGame);
445-
} catch (error) {
446-
log.error("MongoClient.upsertBoardGame", error);
431+
if (this.propertyManager.experimentalBoardGameBoxRendering) {
432+
if (!("primaryColor" in boardGame)) {
433+
try {
434+
const image = sharp(`${paths.FRONTEND_STATIC_DIRECTORY_PATH}${boardGame.coverArtFilePath}`);
435+
const stats = await image.stats();
436+
const primaryColor = stats.dominant;
437+
if (boardGame.primaryColor !== primaryColor) {
438+
boardGame.primaryColor = primaryColor;
439+
try {
440+
await this.upsertBoardGame(boardGame);
441+
} catch (error) {
442+
log.error("MongoClient.upsertBoardGame", error);
443+
}
447444
}
445+
} catch (error) {
446+
log.error("sharp.stats", error);
447+
}
448+
}
449+
if (!("ratio" in boardGame)) {
450+
try {
451+
const image = sharp(`${paths.FRONTEND_STATIC_DIRECTORY_PATH}${boardGame.coverArtFilePath}`);
452+
const metadata = await image.metadata();
453+
const ratio = metadata.width / metadata.height;
454+
455+
if (boardGame.ratio !== ratio) {
456+
boardGame.ratio = ratio;
457+
try {
458+
await this.upsertBoardGame(boardGame);
459+
} catch (error) {
460+
log.error("MongoClient.upsertBoardGame", error);
461+
}
462+
}
463+
} catch (error) {
464+
log.error("sharp.metadata", error);
448465
}
449-
} catch (error) {
450-
log.error("sharp.stats", error);
451466
}
452467
}
453468

0 commit comments

Comments
 (0)