diff --git a/internal/conf/const.go b/internal/conf/const.go index d7fe66b7..322e12de 100644 --- a/internal/conf/const.go +++ b/internal/conf/const.go @@ -17,7 +17,7 @@ const ( AllowMounted = "allow_mounted" RobotsTxt = "robots_txt" - Logo = "logo" + Logo = "logo" // multi-lines text, L1: light, EOL: dark Favicon = "favicon" MainColor = "main_color" diff --git a/server/static/config.go b/server/static/config.go index 19a6e1b7..51d60084 100644 --- a/server/static/config.go +++ b/server/static/config.go @@ -15,7 +15,7 @@ type SiteConfig struct { func getSiteConfig() SiteConfig { siteConfig := SiteConfig{ BasePath: conf.URL.Path, - Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", strings.TrimPrefix(conf.WebVersion, "v"),), + Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", strings.TrimPrefix(conf.WebVersion, "v")), } if siteConfig.BasePath != "" { siteConfig.BasePath = utils.FixAndCleanPath(siteConfig.BasePath) diff --git a/server/static/static.go b/server/static/static.go index 47eabb54..b9bd9343 100644 --- a/server/static/static.go +++ b/server/static/static.go @@ -41,9 +41,8 @@ func replaceStrings(content string, replacements map[string]string) string { return content } -func initIndex() { +func initIndex(siteConfig SiteConfig) { utils.Log.Debug("Initializing index.html...") - siteConfig := getSiteConfig() // dist_dir is empty and cdn is not empty add web_version is empty or beta or dev if conf.Conf.DistDir == "" && conf.Conf.Cdn != "" && (conf.WebVersion == "" || conf.WebVersion == "beta" || conf.WebVersion == "dev") { utils.Log.Infof("Fetching index.html from CDN: %s/index.html...", conf.Conf.Cdn) @@ -89,6 +88,7 @@ func initIndex() { func UpdateIndex() { utils.Log.Debug("Updating index.html with settings...") favicon := setting.GetStr(conf.Favicon) + logo := strings.Split(setting.GetStr(conf.Logo), "\n")[0] title := setting.GetStr(conf.SiteTitle) customizeHead := setting.GetStr(conf.CustomizeHead) customizeBody := setting.GetStr(conf.CustomizeBody) @@ -96,6 +96,7 @@ func UpdateIndex() { utils.Log.Debug("Applying replacements for default pages...") replaceMap1 := map[string]string{ "https://cdn.oplist.org/gh/OpenListTeam/Logo@main/logo.svg": favicon, + "https://cdn.oplist.org/gh/OpenListTeam/Logo@main/logo.png": logo, "Loading...": title, "main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor), } @@ -111,8 +112,9 @@ func UpdateIndex() { func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) { utils.Log.Debug("Setting up static routes...") + siteConfig := getSiteConfig() initStatic() - initIndex() + initIndex(siteConfig) folders := []string{"assets", "images", "streamer", "static"} if conf.Conf.Cdn == "" { utils.Log.Debug("Setting up static file serving...") @@ -136,7 +138,7 @@ func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) { for _, folder := range folders { r.GET(fmt.Sprintf("/%s/*filepath", folder), func(c *gin.Context) { filepath := c.Param("filepath") - c.Redirect(http.StatusFound, fmt.Sprintf("%s/%s%s", conf.Conf.Cdn, folder, filepath)) + c.Redirect(http.StatusFound, fmt.Sprintf("%s/%s%s", siteConfig.Cdn, folder, filepath)) }) } }