feat: add reader endpoint and update TTS link generation with display name

This commit is contained in:
王锦强
2025-03-16 23:29:16 +08:00
parent 1cc4ef556c
commit ebb7e2b292
5 changed files with 99 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"net/url"
"strings"
@@ -157,3 +158,28 @@ func MergeStringsWithLimit(strs []string, minLen int, maxLen int) []string {
return result
}
// GetBaseURL 返回基础 URL包括方案和主机但不包括路径和查询参数
func GetBaseURL(c *gin.Context) string {
scheme := "http"
if c.Request.TLS != nil || c.Request.Header.Get("X-Forwarded-Proto") == "https" {
scheme = "https"
}
return fmt.Sprintf("%s://%s", scheme, c.Request.Host)
}
// JoinURL 安全地拼接基础 URL 和相对路径
func JoinURL(baseURL, relativePath string) (string, error) {
base, err := url.Parse(baseURL)
if err != nil {
return "", err
}
rel, err := url.Parse(relativePath)
if err != nil {
return "", err
}
return base.ResolveReference(rel).String(), nil
}