fix: strip query params from asset URLs before filesystem lookup
All checks were successful
Deploy to Production / test (push) Successful in 36s
All checks were successful
Deploy to Production / test (push) Successful in 36s
Icon URLs stored with cache-busting query params (e.g. ?v=123) caused existsSync to fail, preventing Discord attachment fallback and leaving unresolvable localhost URLs as thumbnails. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
MessageFlags,
|
||||
} from "discord.js";
|
||||
import { resolveAssetUrl, isLocalAssetUrl } from "@shared/lib/assets";
|
||||
import { getRarityConfig, defaultName } from "@shared/lib/rarity";
|
||||
import { getRarityConfig, defaultName, stripQuery } from "@shared/lib/rarity";
|
||||
import { join } from "path";
|
||||
import { existsSync } from "fs";
|
||||
|
||||
@@ -126,7 +126,7 @@ export function getLootboxResultMessage(
|
||||
const iconSource = lootResult.rewardType === "ITEM" ? lootResult.item?.iconUrl : item?.iconUrl;
|
||||
if (iconSource) {
|
||||
if (isLocalAssetUrl(iconSource)) {
|
||||
const iconPath = join(process.cwd(), "bot/assets/graphics", iconSource.replace(/^\/?assets\//, ""));
|
||||
const iconPath = join(process.cwd(), "bot/assets/graphics", stripQuery(iconSource).replace(/^\/?assets\//, ""));
|
||||
if (existsSync(iconPath)) {
|
||||
const iconName = defaultName(iconSource);
|
||||
files.push(new AttachmentBuilder(iconPath, { name: iconName }));
|
||||
@@ -150,7 +150,7 @@ export function getLootboxResultMessage(
|
||||
if (imgSource && imgSource !== iconSrc) {
|
||||
let displayImageUrl: string | null = null;
|
||||
if (isLocalAssetUrl(imgSource)) {
|
||||
const imagePath = join(process.cwd(), "bot/assets/graphics", imgSource.replace(/^\/?assets\//, ""));
|
||||
const imagePath = join(process.cwd(), "bot/assets/graphics", stripQuery(imgSource).replace(/^\/?assets\//, ""));
|
||||
if (existsSync(imagePath)) {
|
||||
const imageName = defaultName(imgSource);
|
||||
if (!files.find(f => f.name === imageName)) {
|
||||
|
||||
Reference in New Issue
Block a user