mirror of https://github.com/Xhofe/alist
refactor!: move `api_url` and `base_path` to config file
parent
03dbb3a403
commit
7c32af4649
|
@ -70,8 +70,8 @@ func InitialSettings() []model.SettingItem {
|
||||||
initialSettingItems = []model.SettingItem{
|
initialSettingItems = []model.SettingItem{
|
||||||
// site settings
|
// site settings
|
||||||
{Key: conf.VERSION, Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
{Key: conf.VERSION, Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
||||||
{Key: conf.ApiUrl, Value: "", Type: conf.TypeString, Group: model.SITE},
|
//{Key: conf.ApiUrl, Value: "", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.BasePath, Value: "", Type: conf.TypeString, Group: model.SITE},
|
//{Key: conf.BasePath, Value: "", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.SiteTitle, Value: "AList", Type: conf.TypeString, Group: model.SITE},
|
{Key: conf.SiteTitle, Value: "AList", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.Announcement, Value: "### repo\nhttps://github.com/alist-org/alist", Type: conf.TypeText, Group: model.SITE},
|
{Key: conf.Announcement, Value: "### repo\nhttps://github.com/alist-org/alist", Type: conf.TypeText, Group: model.SITE},
|
||||||
{Key: "pagination_type", Value: "all", Type: conf.TypeSelect, Options: "all,pagination,load_more,auto_load_more", Group: model.SITE},
|
{Key: "pagination_type", Value: "all", Type: conf.TypeSelect, Options: "all,pagination,load_more,auto_load_more", Group: model.SITE},
|
||||||
|
|
|
@ -35,8 +35,9 @@ type Config struct {
|
||||||
Force bool `json:"force" env:"FORCE"`
|
Force bool `json:"force" env:"FORCE"`
|
||||||
Address string `json:"address" env:"ADDR"`
|
Address string `json:"address" env:"ADDR"`
|
||||||
Port int `json:"port" env:"PORT"`
|
Port int `json:"port" env:"PORT"`
|
||||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
SiteURL string `json:"site_url" env:"SITE_URL"`
|
||||||
Cdn string `json:"cdn" env:"CDN"`
|
Cdn string `json:"cdn" env:"CDN"`
|
||||||
|
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||||
Database Database `json:"database"`
|
Database Database `json:"database"`
|
||||||
Scheme Scheme `json:"scheme"`
|
Scheme Scheme `json:"scheme"`
|
||||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||||
|
|
|
@ -10,15 +10,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetApiUrl(r *http.Request) string {
|
func GetApiUrl(r *http.Request) string {
|
||||||
api := setting.GetStr(conf.ApiUrl)
|
api := conf.Conf.SiteURL
|
||||||
protocol := "http"
|
if api == "" {
|
||||||
if r != nil {
|
api = setting.GetStr(conf.ApiUrl)
|
||||||
|
}
|
||||||
|
if r != nil && api == "" {
|
||||||
|
protocol := "http"
|
||||||
if r.TLS != nil {
|
if r.TLS != nil {
|
||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
if api == "" {
|
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
||||||
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
strings.TrimSuffix(api, "/")
|
strings.TrimSuffix(api, "/")
|
||||||
return api
|
return api
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
stdpath "path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SiteConfig struct {
|
||||||
|
ApiURL string
|
||||||
|
BasePath string
|
||||||
|
Cdn string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSiteConfig() SiteConfig {
|
||||||
|
siteConfig := SiteConfig{
|
||||||
|
ApiURL: conf.Conf.SiteURL,
|
||||||
|
BasePath: stdpath.Base(conf.Conf.SiteURL),
|
||||||
|
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", conf.WebVersion),
|
||||||
|
}
|
||||||
|
// try to get old config
|
||||||
|
if siteConfig.ApiURL == "" {
|
||||||
|
siteConfig.ApiURL = setting.GetStr(conf.ApiUrl)
|
||||||
|
siteConfig.BasePath = setting.GetStr(conf.BasePath)
|
||||||
|
}
|
||||||
|
if siteConfig.BasePath != "" {
|
||||||
|
siteConfig.BasePath = utils.StandardizePath(siteConfig.BasePath)
|
||||||
|
}
|
||||||
|
if siteConfig.Cdn == "" {
|
||||||
|
siteConfig.Cdn = siteConfig.BasePath
|
||||||
|
}
|
||||||
|
return siteConfig
|
||||||
|
}
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/alist-org/alist/v3/cmd/flags"
|
"github.com/alist-org/alist/v3/cmd/flags"
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/setting"
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
|
||||||
"github.com/alist-org/alist/v3/public"
|
"github.com/alist-org/alist/v3/public"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -26,16 +25,7 @@ func InitIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateIndex() {
|
func UpdateIndex() {
|
||||||
cdn := strings.TrimSuffix(conf.Conf.Cdn, "/")
|
siteConfig := getSiteConfig()
|
||||||
cdn = strings.ReplaceAll(cdn, "$version", conf.WebVersion)
|
|
||||||
basePath := setting.GetStr(conf.BasePath)
|
|
||||||
if basePath != "" {
|
|
||||||
basePath = utils.StandardizePath(basePath)
|
|
||||||
}
|
|
||||||
if cdn == "" {
|
|
||||||
cdn = basePath
|
|
||||||
}
|
|
||||||
apiUrl := setting.GetStr(conf.ApiUrl)
|
|
||||||
favicon := setting.GetStr(conf.Favicon)
|
favicon := setting.GetStr(conf.Favicon)
|
||||||
title := setting.GetStr(conf.SiteTitle)
|
title := setting.GetStr(conf.SiteTitle)
|
||||||
customizeHead := setting.GetStr(conf.CustomizeHead)
|
customizeHead := setting.GetStr(conf.CustomizeHead)
|
||||||
|
@ -45,9 +35,9 @@ func UpdateIndex() {
|
||||||
replaceMap1 := map[string]string{
|
replaceMap1 := map[string]string{
|
||||||
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
|
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
|
||||||
"Loading...": title,
|
"Loading...": title,
|
||||||
"cdn: undefined": fmt.Sprintf("cdn: '%s'", cdn),
|
"cdn: undefined": fmt.Sprintf("cdn: '%s'", siteConfig.Cdn),
|
||||||
"base_path: undefined": fmt.Sprintf("base_path: '%s'", basePath),
|
"base_path: undefined": fmt.Sprintf("base_path: '%s'", siteConfig.BasePath),
|
||||||
"api: undefined": fmt.Sprintf("api: '%s'", apiUrl),
|
"api: undefined": fmt.Sprintf("api: '%s'", siteConfig.ApiURL),
|
||||||
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
|
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
|
||||||
}
|
}
|
||||||
for k, v := range replaceMap1 {
|
for k, v := range replaceMap1 {
|
||||||
|
|
Loading…
Reference in New Issue