This commit is contained in:
lizandrogd
2026-01-21 12:26:36 -05:00
parent 901d51c82f
commit b6ef6179b8
3 changed files with 77 additions and 4 deletions
+66 -4
View File
@@ -1357,7 +1357,25 @@
case 'image':
// Usar miniatura local si existe, al abrir expandir con el archivo local completo o con media-url redirect
const thumb = msg.local_thumb ? (`/${msg.local_thumb}`) : (msg.local_file ? (`/${msg.local_file}`) : (msg.media_url_external || mediaUrl));
const full = msg.local_file ? (`/api/version/media-url.php?local=${encodeURIComponent(msg.local_file)}`) : (`/api/version/media-url.php?id=${encodeURIComponent(msg.media_url || '')}`);
let full = '';
if (msg.local_file) {
full = `/api/version/media-url.php?local=${encodeURIComponent(msg.local_file)}`;
} else if (msg.media_url_external) {
// Si viene una ruta del tipo api/get_media.php?id=XXX extraer id
if (msg.media_url_external.indexOf('api/get_media.php?id=') !== -1) {
const parts = msg.media_url_external.split('id=');
const mid = parts[1] ? decodeURIComponent(parts[1]) : '';
full = `/api/version/media-url.php?id=${encodeURIComponent(mid)}`;
} else if (/^https?:\/\//i.test(msg.media_url_external)) {
// URL directa
full = msg.media_url_external;
} else {
// fallback: pasar como url
full = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}`;
}
} else {
full = mediaUrl || '';
}
return `
<div class="message-media">
<img src="${thumb}" alt="Imagen" onclick="window.open('${full}', '_blank')" style="cursor:zoom-in">
@@ -1366,7 +1384,22 @@
`;
case 'video':
const videoSrc = msg.local_file ? (`/${msg.local_file}`) : (msg.media_url_external || mediaUrl);
let videoSrc = '';
if (msg.local_file) {
videoSrc = `/${msg.local_file}`;
} else if (msg.media_url_external) {
if (msg.media_url_external.indexOf('api/get_media.php?id=') !== -1) {
const parts = msg.media_url_external.split('id=');
const mid = parts[1] ? decodeURIComponent(parts[1]) : '';
videoSrc = `/api/version/media-url.php?id=${encodeURIComponent(mid)}`;
} else if (/^https?:\/\//i.test(msg.media_url_external)) {
videoSrc = msg.media_url_external;
} else {
videoSrc = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}`;
}
} else {
videoSrc = mediaUrl;
}
return `
<div class="message-media">
<video controls>
@@ -1378,7 +1411,22 @@
`;
case 'audio':
const audioSrc = msg.local_file ? (`/${msg.local_file}`) : (msg.media_url_external || mediaUrl);
let audioSrc = '';
if (msg.local_file) {
audioSrc = `/${msg.local_file}`;
} else if (msg.media_url_external) {
if (msg.media_url_external.indexOf('api/get_media.php?id=') !== -1) {
const parts = msg.media_url_external.split('id=');
const mid = parts[1] ? decodeURIComponent(parts[1]) : '';
audioSrc = `/api/version/media-url.php?id=${encodeURIComponent(mid)}`;
} else if (/^https?:\/\//i.test(msg.media_url_external)) {
audioSrc = msg.media_url_external;
} else {
audioSrc = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}`;
}
} else {
audioSrc = mediaUrl;
}
return `
<div class="message-media">
<audio controls>
@@ -1390,7 +1438,21 @@
case 'document':
// Para documentos no descargamos automáticamente; abrir la URL externa (o la redirección por media id) para descargar
const docUrl = msg.local_file ? (`/api/version/media-url.php?local=${encodeURIComponent(msg.local_file)}&download=1`) : (`/api/version/media-url.php?id=${encodeURIComponent(msg.media_url || msg.media_url_external || '')}&download=1`);
let docUrl = '';
if (msg.local_file) {
docUrl = `/api/version/media-url.php?local=${encodeURIComponent(msg.local_file)}&download=1`;
} else if (msg.media_url_external) {
if (msg.media_url_external.indexOf('api/get_media.php?id=') !== -1) {
const parts = msg.media_url_external.split('id=');
const mid = parts[1] ? decodeURIComponent(parts[1]) : '';
docUrl = `/api/version/media-url.php?id=${encodeURIComponent(mid)}&download=1`;
} else if (/^https?:\/\//i.test(msg.media_url_external)) {
docUrl = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}&download=1`;
} else {
// fallback
docUrl = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}&download=1`;
}
}
return `
<div class="message-document" onclick="window.open('${docUrl}', '_blank')" style="cursor:pointer">
<i class="fas fa-file-pdf"></i>
+6
View File
@@ -0,0 +1,6 @@
<?php
require_once __DIR__ . '/../config/config.php';
$db = Database::getInstance();
$rows = $db->fetchAll("SELECT id,user_id,message_id,message_type,content,media_url,filename,created_at,local_file,local_thumb FROM conversations WHERE message_type IN ('image','video','audio') AND (local_file IS NULL OR local_file = '') ORDER BY created_at DESC LIMIT 50");
if (!$rows) { echo "No pending media to store\n"; exit; }
echo json_encode($rows, JSON_PRETTY_PRINT) . "\n";
+5
View File
@@ -0,0 +1,5 @@
<?php
require_once __DIR__ . '/../config/config.php';
$db = Database::getInstance();
$rows = $db->fetchAll('SELECT id,user_id,message_id,message_type,content,media_url,local_file,local_thumb,created_at FROM conversations WHERE (local_file IS NOT NULL OR local_thumb IS NOT NULL) ORDER BY created_at DESC LIMIT 20');
echo json_encode($rows, JSON_PRETTY_PRINT) . "\n";