diff --git a/dist/api/send_message.php b/dist/api/send_message.php index 292e858..5582ce3 100644 --- a/dist/api/send_message.php +++ b/dist/api/send_message.php @@ -7,7 +7,7 @@ header('Cache-Control: no-store'); require __DIR__ . '/im_web_bootstrap.php'; const WEB_MEDIA_ROOT = '/opt/im-server/media'; -const WEB_MEDIA_PUBLIC_PORT = 18000; +define('WEB_MEDIA_PUBLIC_PORT', (int)webImEnv('JC_WEB_IM_MEDIA_PORT', '80')); const WEB_MEDIA_TYPE_IMAGE = 1; const WEB_MEDIA_TYPE_FILE = 4; const WEB_IMAGE_MAX_BYTES = 10 * 1024 * 1024; @@ -154,8 +154,12 @@ function mediaPublicBaseUrl(): string $isHttps = (string)($_SERVER['HTTPS'] ?? '') !== '' && strtolower((string)$_SERVER['HTTPS']) !== 'off'; $scheme = $isHttps ? 'https' : 'http'; $host = trim(preg_replace('/:\d+$/', '', (string)($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? '127.0.0.1')) ?: '127.0.0.1'); + $port = (int)WEB_MEDIA_PUBLIC_PORT; + if ($port <= 0 || ($scheme === 'http' && $port === 80) || ($scheme === 'https' && $port === 443)) { + return $scheme . '://' . $host; + } - return $scheme . '://' . $host . ':' . WEB_MEDIA_PUBLIC_PORT; + return $scheme . '://' . $host . ':' . $port; } function saveMessageAttachmentFile(array $file, string $attachmentType): array diff --git a/public/api/send_message.php b/public/api/send_message.php index 292e858..5582ce3 100644 --- a/public/api/send_message.php +++ b/public/api/send_message.php @@ -7,7 +7,7 @@ header('Cache-Control: no-store'); require __DIR__ . '/im_web_bootstrap.php'; const WEB_MEDIA_ROOT = '/opt/im-server/media'; -const WEB_MEDIA_PUBLIC_PORT = 18000; +define('WEB_MEDIA_PUBLIC_PORT', (int)webImEnv('JC_WEB_IM_MEDIA_PORT', '80')); const WEB_MEDIA_TYPE_IMAGE = 1; const WEB_MEDIA_TYPE_FILE = 4; const WEB_IMAGE_MAX_BYTES = 10 * 1024 * 1024; @@ -154,8 +154,12 @@ function mediaPublicBaseUrl(): string $isHttps = (string)($_SERVER['HTTPS'] ?? '') !== '' && strtolower((string)$_SERVER['HTTPS']) !== 'off'; $scheme = $isHttps ? 'https' : 'http'; $host = trim(preg_replace('/:\d+$/', '', (string)($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? '127.0.0.1')) ?: '127.0.0.1'); + $port = (int)WEB_MEDIA_PUBLIC_PORT; + if ($port <= 0 || ($scheme === 'http' && $port === 80) || ($scheme === 'https' && $port === 443)) { + return $scheme . '://' . $host; + } - return $scheme . '://' . $host . ':' . WEB_MEDIA_PUBLIC_PORT; + return $scheme . '://' . $host . ':' . $port; } function saveMessageAttachmentFile(array $file, string $attachmentType): array