From 051f60aaf090e8a99d6d0d1d46c28b845ed04f08 Mon Sep 17 00:00:00 2001 From: winchen Date: Tue, 30 Jun 2026 15:55:24 +0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AA=92=E4=BD=93=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E7=9B=AE=E5=BD=95=E5=92=8C=E5=9C=B0=E5=9D=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/api/send_message.php | 8 ++++++-- public/api/send_message.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) 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