diff --git a/controllers/chat.py b/controllers/chat.py
index 6477833..4a35de9 100644
--- a/controllers/chat.py
+++ b/controllers/chat.py
@@ -83,6 +83,7 @@ def register_routes(app):
channel = data.get("channel", "general")
content = data.get("message", "").strip()
+ gif_url = data.get("gif_url") or None
if channel not in VALID_CHANNELS:
response.status = 400
@@ -97,7 +98,7 @@ def register_routes(app):
content = _strip_xss(content)
ip_hash = hashlib.sha256((_salt + ip).encode()).hexdigest()[:16]
- msg_id = _db.add_message(channel, ip_hash, content)
+ msg_id = _db.add_message(channel, ip_hash, content, gif_url=gif_url)
return {"success": True, "message_id": msg_id, "ip": ip_hash}
except Exception as e:
diff --git a/index.html b/index.html
index 4e452bf..1796142 100644
--- a/index.html
+++ b/index.html
@@ -320,8 +320,10 @@
return;
}
gifGrid.innerHTML = results.map(gif => {
- const url = gif.media_formats?.tinygif?.url || gif.url;
- return ``;
+ // Use the actual media URL, not the Tenor page URL
+ const thumbUrl = gif.media_formats?.tinygif?.url || gif.media_formats?.gif?.url || gif.url;
+ const fullUrl = gif.media_formats?.gif?.url || thumbUrl;
+ return `
`;
}).join('');
gifGrid.querySelectorAll('img').forEach(img => {
@@ -395,11 +397,16 @@
let html = '';
msgs.forEach(msg => {
const time = new Date(msg.timestamp).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
- let contentHtml = escapeHtml(msg.content);
- // Render inline GIFs from stored
tags
- contentHtml = contentHtml.replace(/<img class="inline-gif" src="(.*?)">/g, (_, url) => {
- return `
`;
- });
+ let contentHtml = escapeHtml(msg.content || '');
+ // Try gif_url from API first, fallback to parsing content for old messages
+ let gifToShow = msg.gif_url || null;
+ if (!gifToShow) {
+ const gifMatch = msg.content.match(/https?:\/\/[^\s]+\.(gif|webp)(\?[^\s]*)?/i);
+ if (gifMatch) gifToShow = gifMatch[0];
+ }
+ if (gifToShow) {
+ contentHtml += `
`;
+ }
html += `