2022-06-29 08:08:55 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
2022-08-03 06:26:59 +00:00
|
|
|
|
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
|
|
|
"github.com/alist-org/alist/v3/internal/setting"
|
2022-06-29 08:08:55 +00:00
|
|
|
)
|
|
|
|
|
2022-08-11 12:32:17 +00:00
|
|
|
func GetApiUrl(r *http.Request) string {
|
2022-09-25 09:57:54 +00:00
|
|
|
api := conf.Conf.SiteURL
|
|
|
|
if api == "" {
|
|
|
|
api = setting.GetStr(conf.ApiUrl)
|
|
|
|
}
|
|
|
|
if r != nil && api == "" {
|
|
|
|
protocol := "http"
|
2022-08-11 12:32:17 +00:00
|
|
|
if r.TLS != nil {
|
|
|
|
protocol = "https"
|
|
|
|
}
|
2022-09-25 09:57:54 +00:00
|
|
|
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
|
|
|
|
2022-06-30 14:41:55 +00:00
|
|
|
}
|
2022-08-11 12:32:17 +00:00
|
|
|
strings.TrimSuffix(api, "/")
|
|
|
|
return api
|
2022-06-29 08:08:55 +00:00
|
|
|
}
|