Skip to content

Commit

Permalink
加载配置以支持强制SSL设置,并根据配置更新服务器端口
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuki-nya committed Nov 23, 2024
1 parent 3aff438 commit 8cd177e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/uploadpic.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ func UploadBase64ImageHandlerV3(rateLimiter *RateLimiter, apiv1 openapi.OpenAPI)
// 闭包,网页后端,语音床逻辑,基于gin和www静态文件的简易语音床
func UploadBase64RecordHandler(rateLimiter *RateLimiter) gin.HandlerFunc {
return func(c *gin.Context) {
// 加载配置
conf, err := config.LoadConfig("config.yml", false)
if err != nil {
mylog.Fatalf("error: %v", err)
}

ipAddress := c.ClientIP()
if !rateLimiter.CheckAndUpdateRateLimit(ipAddress) {
c.JSON(http.StatusTooManyRequests, gin.H{"error": "rate limit exceeded"})
Expand Down Expand Up @@ -288,8 +294,9 @@ func UploadBase64RecordHandler(rateLimiter *RateLimiter) gin.HandlerFunc {

// 根据serverPort确定协议
protocol := "http"
if serverPort == "443" {
if serverPort == "443" || conf.Settings.ForceSSL {
protocol = "https"
serverPort = conf.Settings.Port
}

imageURL := fmt.Sprintf("%s://%s:%s/channel_temp/%s", protocol, serverAddress, serverPort, fileName)
Expand Down

0 comments on commit 8cd177e

Please sign in to comment.