Do not replace inline HTML img with image embed (#4063)

89ef54f2869392e32f3d89cde55f0c4d3c0c536e

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +6 -23Showing whitespace changes
public/script.js+6 -23
@@ -3566,7 +3566,7 @@ class StreamingProcessor {
35663566 }
35673567
35683568 if (this.image) {
35693569 await processImageAttachment(chat[messageId], { imageUrl: this.image, parsedImage: null });
35703570 appendMediaToMessage(chat[messageId], $(this.messageDom));
35713571 }
35723572
@@ -6309,17 +6309,11 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI
63096309 * Adds an image to the message.
63106310 * @param {object} message Message object
63116311 * @param {object} sources Image sources
6312- * @param {ParsedImage} [sources.parsedImage] Parsed image
63136312 * @param {string} [sources.imageUrl] Image URL
63146313 *
63156314 * @returns {Promise<void>}
63166315 */
63176316async function processImageAttachment(message, { parsedImage, imageUrl }) {
6318- if (parsedImage?.image) {
6319- saveImageToMessage(parsedImage, message);
6320- return;
6321- }
6322-
63236317 if (!imageUrl) {
63246318 return;
63256319 }
@@ -6378,8 +6372,6 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
63786372
63796373 let oldMessage = '';
63806374 const generationFinished = new Date();
6381- const parsedImage = extractImageFromMessage(getMessage);
6382- getMessage = parsedImage.getMessage;
63836375 if (type === 'swipe') {
63846376 oldMessage = chat[chat.length - 1]['mes'];
63856377 chat[chat.length - 1]['swipes'].length++;
@@ -6393,7 +6385,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
63936385 chat[chat.length - 1]['extra']['model'] = getGeneratingModel();
63946386 chat[chat.length - 1]['extra']['reasoning'] = reasoning;
63956387 chat[chat.length - 1]['extra']['reasoning_duration'] = null;
63966388 await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl });
63976389 if (power_user.message_token_count_enabled) {
63986390 const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes'];
63996391 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
@@ -6417,7 +6409,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
64176409 chat[chat.length - 1]['extra']['model'] = getGeneratingModel();
64186410 chat[chat.length - 1]['extra']['reasoning'] = reasoning;
64196411 chat[chat.length - 1]['extra']['reasoning_duration'] = null;
64206412 await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl });
64216413 if (power_user.message_token_count_enabled) {
64226414 const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes'];
64236415 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
@@ -6437,7 +6429,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
64376429 chat[chat.length - 1]['extra']['api'] = getGeneratingApi();
64386430 chat[chat.length - 1]['extra']['model'] = getGeneratingModel();
64396431 chat[chat.length - 1]['extra']['reasoning'] += reasoning;
64406432 await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl });
64416433 // We don't know if the reasoning duration extended, so we don't update it here on purpose.
64426434 if (power_user.message_token_count_enabled) {
64436435 const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes'];
@@ -6483,7 +6475,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
64836475 chat[chat.length - 1]['extra']['gen_id'] = group_generation_id;
64846476 }
64856477
64866478 await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl: imageUrl });
64876479 const chat_id = (chat.length - 1);
64886480
64896481 !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
@@ -6700,15 +6692,6 @@ function getGeneratingModel(mes) {
67006692 return model;
67016693}
67026694
6703-function extractImageFromMessage(getMessage) {
6704- const regex = /<img src="(.*?)".*?alt="(.*?)".*?>/g;
6705- const results = regex.exec(getMessage);
6706- const image = results ? results[1] : '';
6707- const title = results ? results[2] : '';
6708- getMessage = getMessage.replace(regex, '');
6709- return { getMessage, image, title, inline: true };
6710-}
6711-
67126695/**
67136696 * A function mainly used to switch 'generating' state - setting it to false and activating the buttons again
67146697 */