diff --git a/api/chat.php b/api/chat.php
index a6a059e..38a117d 100644
--- a/api/chat.php
+++ b/api/chat.php
@@ -7,7 +7,20 @@ $method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
try {
- // Limpiar mensajes y archivos de más de 6 horas
+ // Borrar fotos (tipo image) que tengan más de 5 segundos
+ $stOld = db()->prepare("SELECT message FROM messages WHERE type = 'image' AND created_at < DATE_SUB(NOW(), INTERVAL 5 SECOND)");
+ $stOld->execute();
+ $imagesToDelete = $stOld->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($imagesToDelete as $img) {
+ $path = __DIR__ . '/../' . $img['message'];
+ if (file_exists($path) && is_file($path)) {
+ unlink($path);
+ }
+ }
+ db()->query("DELETE FROM messages WHERE type = 'image' AND created_at < DATE_SUB(NOW(), INTERVAL 5 SECOND)");
+
+ // Limpiar otros mensajes y archivos de más de 6 horas
$oldImages = db()->prepare("SELECT message FROM messages WHERE type = 'image' AND created_at < DATE_SUB(NOW(), INTERVAL 6 HOUR)");
$oldImages->execute();
$filesToDelete = $oldImages->fetchAll(PDO::FETCH_ASSOC);
diff --git a/api/gallery.php b/api/gallery.php
index e9ecb08..629def0 100644
--- a/api/gallery.php
+++ b/api/gallery.php
@@ -7,6 +7,19 @@ $method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
try {
+ // Borrar fotos de la galería que tengan más de 5 segundos
+ $stOld = db()->prepare("SELECT image_url FROM gallery WHERE created_at < DATE_SUB(NOW(), INTERVAL 5 SECOND)");
+ $stOld->execute();
+ $imagesToDelete = $stOld->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($imagesToDelete as $img) {
+ $path = __DIR__ . '/../' . $img['image_url'];
+ if (file_exists($path) && is_file($path)) {
+ // unlink($path); // Opcional: borrar el archivo físico.
+ // Pero si viene del chat, el chat ya lo borra si habilitamos lo mismo ahí.
+ }
+ }
+ db()->query("DELETE FROM gallery WHERE created_at < DATE_SUB(NOW(), INTERVAL 5 SECOND)");
+
$stmt = db()->prepare("SELECT * FROM gallery ORDER BY created_at DESC LIMIT 50");
$stmt->execute();
$images = $stmt->fetchAll(PDO::FETCH_ASSOC);
diff --git a/index.php b/index.php
index 279dea5..809e3ce 100644
--- a/index.php
+++ b/index.php
@@ -2374,7 +2374,12 @@ $twitter_link = "https://twitter.com/";
let content = '';
if (msg.type === 'image') {
- content = ``;
+ content = `
+