up
This commit is contained in:
@@ -290,6 +290,44 @@ if ($wantsJson) {
|
||||
|
||||
// Si se pidió proxy (download=1), traer el contenido y retornarlo como descarga
|
||||
if ($download) {
|
||||
// Si la URL apunta al mismo servidor (localhost/127.0.0.1 o al host actual), no usar curl (evita deadlocks en PHP built-in server)
|
||||
$parsedUrl = parse_url($mediaUrl);
|
||||
$host = isset($parsedUrl['host']) ? strtolower($parsedUrl['host']) : '';
|
||||
$port = isset($parsedUrl['port']) ? $parsedUrl['port'] : null;
|
||||
|
||||
$isLocalHost = in_array($host, ['127.0.0.1', 'localhost']) || ($host && isset($_SERVER['HTTP_HOST']) && stripos($_SERVER['HTTP_HOST'], $host) !== false);
|
||||
|
||||
if ($isLocalHost) {
|
||||
media_log("Serving local file directly for URL: {$mediaUrl}");
|
||||
|
||||
// Mapear path a archivo local seguro
|
||||
$path = $parsedUrl['path'] ?? '';
|
||||
// Asumir que los archivos subidos están en uploads/
|
||||
$localPath = realpath(__DIR__ . '/../../' . ltrim($path, '/'));
|
||||
$base = realpath(__DIR__ . '/../../uploads');
|
||||
|
||||
if (!$localPath || strpos($localPath, $base) !== 0 || !file_exists($localPath)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode(['success' => false, 'error' => 'Archivo local no encontrado o ruta inválida', 'path' => $localPath]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Determinar mime type
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$contentType = finfo_file($finfo, $localPath);
|
||||
finfo_close($finfo);
|
||||
|
||||
header_remove('Content-Type');
|
||||
header('Cache-Control: public, max-age=3600');
|
||||
if (!empty($contentType)) header('Content-Type: ' . $contentType);
|
||||
header('Content-Length: ' . filesize($localPath));
|
||||
header('Content-Disposition: attachment; filename="' . basename($localPath) . '"');
|
||||
readfile($localPath);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Si no es local, hacer curl normal (incluye Authorization si aplica)
|
||||
$ch = curl_init();
|
||||
// Añadir Authorization si existe token en configuración
|
||||
$token = getConfigFromDB('whatsapp_token', '');
|
||||
|
||||
@@ -20,3 +20,24 @@
|
||||
[2026-01-21 14:19:26] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:19:26] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:19:27] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769023457&hash=ARleg2ej-5Ypy9H7zywh-D2Y08uzbRBDLZvqCKFPAqdN4g
|
||||
[2026-01-21 14:29:48] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:29:48] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:29:49] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769024079&hash=ARmHfwDhkYqc87xd4jXybAeb9ffj3GnkkBhs0e52VtnFOg
|
||||
[2026-01-21 14:30:20] Request: GET /api/version/media-url.php?url=http%3A%2F%2F127.0.0.1%3A8000%2Fuploads%2Fmedia_69712939441cb8.59251559.xlsx&download=1 GET:{"url":"http:\/\/127.0.0.1:8000\/uploads\/media_69712939441cb8.59251559.xlsx","download":"1"} POST:[]
|
||||
[2026-01-21 14:31:30] Request: GET /api/version/media-url.php?url=http%3A%2F%2F127.0.0.1%3A8000%2Fuploads%2Fmedia_69712939441cb8.59251559.xlsx&download=1 GET:{"url":"http:\/\/127.0.0.1:8000\/uploads\/media_69712939441cb8.59251559.xlsx","download":"1"} POST:[]
|
||||
[2026-01-21 14:33:27] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:33:27] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:33:27] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769024297&hash=ARkBPTasx5on_6QDJs2baPhBGoihZq5Z5c4vzkSfrPBjQA
|
||||
[2026-01-21 14:33:32] Request: GET /api/version/media-url.php?url=http%3A%2F%2F127.0.0.1%3A8000%2Fuploads%2Fmedia_69712939441cb8.59251559.xlsx&download=1 GET:{"url":"http:\/\/127.0.0.1:8000\/uploads\/media_69712939441cb8.59251559.xlsx","download":"1"} POST:[]
|
||||
[2026-01-21 14:33:32] Serving local file directly for URL: http://127.0.0.1:8000/uploads/media_69712939441cb8.59251559.xlsx
|
||||
[2026-01-21 14:33:40] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:33:40] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:33:41] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769024311&hash=ARksncZdPSkgk9XaVJ3KveKlf2T0pAHd-KxkY-Y4RK31oA
|
||||
[2026-01-21 14:35:45] Request: GET /api/version/media-url.php?url=http%3A%2F%2F127.0.0.1%3A8000%2Fuploads%2Fmedia_69712939441cb8.59251559.xlsx&download=1 GET:{"url":"http:\/\/127.0.0.1:8000\/uploads\/media_69712939441cb8.59251559.xlsx","download":"1"} POST:[]
|
||||
[2026-01-21 14:35:45] Serving local file directly for URL: http://127.0.0.1:8000/uploads/media_69712939441cb8.59251559.xlsx
|
||||
[2026-01-21 14:35:56] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:35:56] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:35:57] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769024447&hash=ARnjjYGswWnH1Qjxi8vvJC4ZGyD5Z9MBWIqcJfjSoNreow
|
||||
[2026-01-21 14:36:28] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[]
|
||||
[2026-01-21 14:36:28] Graph API request to https://graph.facebook.com/v22.0/3932473397057815
|
||||
[2026-01-21 14:36:28] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769024478&hash=ARnqos_pCP3NfJt-KYcvnkTwjW6kr9XG7VcoVUSjRh6YAQ
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[21-Jan-2026 14:30:20 America/Bogota] PHP Warning: preg_match(): Unknown modifier '&' in C:\laragon\www\whatsapp\api\version\media-url.php on line 131
|
||||
[21-Jan-2026 14:31:30 America/Bogota] PHP Warning: preg_match(): Unknown modifier '&' in C:\laragon\www\whatsapp\api\version\media-url.php on line 131
|
||||
[21-Jan-2026 14:33:32 America/Bogota] PHP Warning: preg_match(): Unknown modifier '&' in C:\laragon\www\whatsapp\api\version\media-url.php on line 131
|
||||
[21-Jan-2026 14:35:45 America/Bogota] PHP Warning: preg_match(): Unknown modifier '&' in C:\laragon\www\whatsapp\api\version\media-url.php on line 131
|
||||
Reference in New Issue
Block a user