fix: keep remote image markdown when normalization fails
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-02-16 11:40:04 +08:00
parent 947495ccfb
commit e4315282a2

View File

@ -929,18 +929,37 @@ async function normalizeAssistantImageMarkdown(
altText, altText,
thumbnailUrl thumbnailUrl
); );
const hostedThumbnailUrl = await ensureHostedImageUrl(thumbnailUrl);
const hostedOriginalUrl =
originalUrl && originalUrl !== thumbnailUrl
? await ensureHostedImageUrl(originalUrl)
: hostedThumbnailUrl;
uploadedUrls.push(hostedThumbnailUrl); let hostedThumbnailUrl = thumbnailUrl;
uploadedUrls.push(hostedOriginalUrl); let hostedOriginalUrl =
rebuilt += `![thumb|||${hostedOriginalUrl}|||${parsedImageSize || imageSize}](${hostedThumbnailUrl})`; originalUrl && originalUrl !== thumbnailUrl ? originalUrl : thumbnailUrl;
try {
hostedThumbnailUrl = await ensureHostedImageUrl(thumbnailUrl);
} catch (error) {
console.error("[Chat API] Failed to normalize remote thumbnail URL:", error);
}
if (originalUrl && originalUrl !== thumbnailUrl) {
try {
hostedOriginalUrl = await ensureHostedImageUrl(originalUrl);
} catch (error) {
console.error("[Chat API] Failed to normalize remote original URL:", error);
hostedOriginalUrl = hostedThumbnailUrl || originalUrl;
}
} else {
hostedOriginalUrl = hostedThumbnailUrl;
}
const finalThumbnailUrl = hostedThumbnailUrl || thumbnailUrl;
const finalOriginalUrl = hostedOriginalUrl || finalThumbnailUrl;
uploadedUrls.push(finalThumbnailUrl);
uploadedUrls.push(finalOriginalUrl);
rebuilt += `![thumb|||${finalOriginalUrl}|||${parsedImageSize || imageSize}](${finalThumbnailUrl})`;
} catch (error) { } catch (error) {
console.error("[Chat API] Failed to normalize remote image URL:", error); console.error("[Chat API] Failed to parse remote image markdown metadata:", error);
rebuilt += ""; rebuilt += matchText;
} }
cursor = start + matchText.length; cursor = start + matchText.length;