fix dall-e-3 don't try to run marked on base64 images.
modified: app.py modified: templates/chat.html
This commit is contained in:
parent
8a626501b3
commit
7d6fe1b27b
2 changed files with 19 additions and 3 deletions
2
app.py
2
app.py
|
|
@ -57,7 +57,7 @@ class Message(db.Model):
|
|||
return self.token_count
|
||||
|
||||
def is_base64_image(self):
|
||||
return '<img src="data:image/jpeg;base64,' in self.content
|
||||
return self.content.startswith('<img src="data:image/jpeg;base64,')
|
||||
|
||||
|
||||
def get_room(room_name):
|
||||
|
|
|
|||
|
|
@ -259,7 +259,15 @@ socket.on("message", (data) => {
|
|||
const newMessage = document.createElement("p");
|
||||
// Check if the username is present and prepend it to the message content
|
||||
const messageContent = data.username ? `**${data.username}:**\n\n${data.content}` : data.content;
|
||||
newMessage.innerHTML = DOMPurify.sanitize(marked.marked(messageContent), dompurify_config);
|
||||
|
||||
// Check if the message starts with a base64 image tag
|
||||
if (data.content.startsWith('<img src="data:image/jpeg;base64')) {
|
||||
// Directly assign the message as innerHTML if it starts with a base64 image
|
||||
newMessage.innerHTML = data.content;
|
||||
} else {
|
||||
// Otherwise, sanitize and process the message with marked
|
||||
newMessage.innerHTML = DOMPurify.sanitize(marked.marked(messageContent), dompurify_config);
|
||||
}
|
||||
|
||||
// Check if the message has an id which means we can delete it.
|
||||
if (data.id) {
|
||||
|
|
@ -293,7 +301,15 @@ socket.on("previous_messages", (data) => {
|
|||
messageWrapper.id = "message-" + data.id;
|
||||
|
||||
const newMessage = document.createElement("p");
|
||||
newMessage.innerHTML = DOMPurify.sanitize(marked.marked(`**${data.username}:**\n\n${data.message}`), dompurify_config);
|
||||
|
||||
// Check if the message contains a base64 image
|
||||
if (data.message.startsWith('<img src="data:image/jpeg;base64')) {
|
||||
// Directly assign the message as innerHTML if it's a base64 image
|
||||
newMessage.innerHTML = data.message;
|
||||
} else {
|
||||
// Otherwise, sanitize and process the message with marked
|
||||
newMessage.innerHTML = DOMPurify.sanitize(marked.marked(`**${data.username}:**\n\n${data.message}`), dompurify_config);
|
||||
}
|
||||
|
||||
// Create the delete button
|
||||
const deleteButton = document.createElement("button");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue