From 88ec58a15a3a6961b2420150cb5c2fde9cc6089b Mon Sep 17 00:00:00 2001 From: leon <916117771@qq.com> Date: Fri, 10 Apr 2026 10:31:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(ota):=20=E4=BF=AE=E5=A4=8DAPK=E4=B8=8B?= =?UTF-8?q?=E8=BD=BDURL=E6=9E=84=E5=BB=BA=E4=B8=AD=E7=9A=84=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=B7=AF=E5=BE=84=E5=89=8D=E7=BC=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 兼容数据库中可能出现的重复 /uploads/ 前缀 - 更新相对路径参数描述,支持可能含 /uploads/ 前缀的情况 - 移除强制HTTPS协议的冗余注释 - 添加正则表达式去除重复的 /uploads/ 前缀 - 简化路径拼接逻辑,避免重复前缀导致的URL错误 --- application/api/controller/Ota.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/api/controller/Ota.php b/application/api/controller/Ota.php index af5bf85..6f6cd0f 100644 --- a/application/api/controller/Ota.php +++ b/application/api/controller/Ota.php @@ -111,17 +111,19 @@ class Ota extends Api * 构建 APK 下载 URL * * 客户端要求必须使用 HTTPS 协议,此处强制转换为 HTTPS。 + * 兼容数据库中可能出现的重复 /uploads/ 前缀。 * - * @param string $relativePath 相对路径(FastAdmin 已含 /uploads/ 前缀) + * @param string $relativePath 相对路径(可能含 /uploads/ 前缀) * @return string 完整 HTTPS URL */ private function buildApkUrl($relativePath) { $domain = request()->domain(); - // 强制使用 HTTPS,客户端要求 downloadUrl 必须以 https:// 开头 + // 强制使用 HTTPS $domain = preg_replace('/^http:\/\//i', 'https://', $domain); - // FastAdmin 存储的路径已含 /uploads/ 前缀,直接拼接即可 - return rtrim($domain, '/') . '/' . ltrim($relativePath, '/'); + // 去除重复的 /uploads/ 前缀(如 /uploads/uploads/ → /uploads/) + $relativePath = preg_replace('#^/?(uploads/)+#', 'uploads/', $relativePath); + return rtrim($domain, '/') . '/' . $relativePath; } /**