Skip to content

Commit

Permalink
fix: incorrect base_path from site_url (close #1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 27, 2022
1 parent 2fc0ccb commit b747965
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions server/static/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package static

import (
stdpath "path"
"net/url"
"strings"

"github.com/alist-org/alist/v3/internal/conf"
Expand All @@ -16,9 +16,13 @@ type SiteConfig struct {
}

func getSiteConfig() SiteConfig {
u, err := url.Parse(conf.Conf.SiteURL)
if err != nil {
utils.Log.Fatalf("can't parse site_url: %+v", err)
}
siteConfig := SiteConfig{
ApiURL: conf.Conf.SiteURL,
BasePath: stdpath.Base(conf.Conf.SiteURL),
BasePath: u.Path,
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", conf.WebVersion),
}
// try to get old config
Expand Down
13 changes: 9 additions & 4 deletions server/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ func InitIndex() {
log.Fatalf("failed to read index.html: %v", err)
}
conf.RawIndexHtml = string(index)
siteConfig := getSiteConfig()
replaceMap := map[string]string{
"cdn: undefined": fmt.Sprintf("cdn: '%s'", siteConfig.Cdn),
"base_path: undefined": fmt.Sprintf("base_path: '%s'", siteConfig.BasePath),
"api: undefined": fmt.Sprintf("api: '%s'", siteConfig.ApiURL),
}
for k, v := range replaceMap {
conf.RawIndexHtml = strings.Replace(conf.RawIndexHtml, k, v, 1)
}
UpdateIndex()
}

func UpdateIndex() {
siteConfig := getSiteConfig()
favicon := setting.GetStr(conf.Favicon)
title := setting.GetStr(conf.SiteTitle)
customizeHead := setting.GetStr(conf.CustomizeHead)
Expand All @@ -35,9 +43,6 @@ func UpdateIndex() {
replaceMap1 := map[string]string{
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
"Loading...": title,
"cdn: undefined": fmt.Sprintf("cdn: '%s'", siteConfig.Cdn),
"base_path: undefined": fmt.Sprintf("base_path: '%s'", siteConfig.BasePath),
"api: undefined": fmt.Sprintf("api: '%s'", siteConfig.ApiURL),
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
}
for k, v := range replaceMap1 {
Expand Down

0 comments on commit b747965

Please sign in to comment.