发货链接返回完整域名:DELIVERY_BASE_URL 未配置时按请求 scheme+Host 推导

- GetOrCreateDeliveryLink/RestoreDeliveryLink 增加 requestBaseURL 参数
- buildDeliveryURL 优先级:DELIVERY_BASE_URL → 请求域名 → 路径
- 支持 X-Forwarded-Proto 与 TLS 判断 https
This commit is contained in:
yml2213
2026-08-03 17:38:11 +08:00
parent 19ada1282e
commit 2e67e2cc3b
5 changed files with 37 additions and 15 deletions
+18
View File
@@ -0,0 +1,18 @@
package handler
import (
"strings"
"github.com/gin-gonic/gin"
)
// requestBaseURL 根据当前请求推导站点基础地址(如 https://skin.khhao.com)。
// 优先取配置的 DELIVERY_BASE_URL(服务层),为空时由请求的 scheme + Host 推导,
// 保证发货链接始终返回完整可访问的 URL。
func requestBaseURL(c *gin.Context) string {
scheme := "http"
if c.Request.TLS != nil || strings.EqualFold(c.GetHeader("X-Forwarded-Proto"), "https") {
scheme = "https"
}
return scheme + "://" + c.Request.Host
}