mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 20:26:26 +08:00
refactor: pass api_url
through context (#457)
* refactor: pass `api_url` through context * 移除 LinkArgs.HttpReq * pref(alias): 减少不必要下载代理 * 修复bug * net: 支持1并发 分片下载
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
stdpath "path"
|
||||
@ -9,7 +10,7 @@ import (
|
||||
"github.com/OpenListTeam/OpenList/internal/conf"
|
||||
)
|
||||
|
||||
func GetApiUrl(r *http.Request) string {
|
||||
func GetApiUrlFormRequest(r *http.Request) string {
|
||||
api := conf.Conf.SiteURL
|
||||
if strings.HasPrefix(api, "http") {
|
||||
return strings.TrimSuffix(api, "/")
|
||||
@ -28,3 +29,11 @@ func GetApiUrl(r *http.Request) string {
|
||||
api = strings.TrimSuffix(api, "/")
|
||||
return api
|
||||
}
|
||||
|
||||
func GetApiUrl(ctx context.Context) string {
|
||||
val := ctx.Value(conf.ApiUrlKey)
|
||||
if api, ok := val.(string); ok {
|
||||
return api
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user