Skip to content

Commit

Permalink
Merge pull request #253 from libsgh/dev
Browse files Browse the repository at this point in the history
v3.0.3
  • Loading branch information
libsgh authored Mar 7, 2022
2 parents 2f5215d + ec81d49 commit 78b23c8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
9 changes: 4 additions & 5 deletions boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,20 @@ func InitStaticBox(r *gin.Engine, fs embed.FS) {
}

func Templates(fs embed.FS) *template.Template {
themes := [6]string{"mdui", "mdui-light", "mdui-dark", "classic", "bootstrap", "materialdesign"}
themes := [3]string{"mdui", "classic", "bootstrap"}
tmpl := template.New("")
templatesFileNames := []string{"base", "appearance", "common", "disk", "hide", "login", "pwd", "safety", "view", "bypass", "cache", "webdav"}
addTemplatesFromFolder("admin", tmpl, fs, templatesFileNames)
for _, theme := range themes {
tmpName := strings.Join([]string{"templates/pan/", "/index.html"}, theme)
tmpFile := strings.ReplaceAll(tmpName, "-dark", "")
tmpFile = strings.ReplaceAll(tmpFile, "-light", "")
theme = util.GetCurrentTheme(theme)
tmpFile := strings.Join([]string{"templates/pan/", "/index.html"}, theme)
dataBuf, _ := fs.ReadFile(tmpFile)
data := string(dataBuf)
if util.FileExist("./templates/" + tmpFile) {
s, _ := ioutil.ReadFile("./templates/" + tmpFile)
data = string(s)
}
tmpl.New(tmpName).Funcs(template.FuncMap{
tmpl.New(tmpFile).Funcs(template.FuncMap{
"unescaped": unescaped,
"contains": strings.Contains,
"iconclass": iconclass,
Expand Down
2 changes: 1 addition & 1 deletion control/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func AdminIndex(c *gin.Context) {

//admin config managent
func ConfigManagent(c *gin.Context) {
middleware.ThemeCheck(c)
middleware.AdminThemeCheck(c)
theme := c.GetString("theme")
fullPath := c.Request.URL.Path
adminModule := strings.Split(fullPath, "/")[2]
Expand Down
7 changes: 3 additions & 4 deletions control/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
func index(c *gin.Context) {
var fns []module.FileNode
var isFile bool
tmpFile := strings.Join([]string{"templates/pan/", "/index.html"}, module.GloablConfig.Theme)
tmpFile := strings.Join([]string{"templates/pan/", "/index.html"}, util.GetCurrentTheme(module.GloablConfig.Theme))
fmt.Println(tmpFile)
account, _ := c.Get("account")
sortColumn := c.GetString("sort_column")
sortOrder := c.GetString("sort_order")
Expand Down Expand Up @@ -150,9 +151,7 @@ func DataRroxy(ac module.Account, downUrl, fileName string, c *gin.Context) {
}

func view(tmpFile *string, viewType string) {
theme := strings.ReplaceAll(module.GloablConfig.Theme, "-dark", "")
theme = strings.ReplaceAll(theme, "-light", "")
*tmpFile = fmt.Sprintf("templates/pan/%s/view-%s.html", theme, viewType)
*tmpFile = fmt.Sprintf("templates/pan/%s/view-%s.html", util.GetCurrentTheme(module.GloablConfig.Theme), viewType)
}

func ShortRedirect(c *gin.Context) {
Expand Down
19 changes: 18 additions & 1 deletion control/middleware/pwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,29 @@ func VerifyPwd(pwd, path, cookiepwd string) (bool, string) {
func ThemeCheck(c *gin.Context) {
theme, err := c.Request.Cookie("theme")
if err != nil {
c.Set("theme", "mdui")
c.Set("theme", module.GloablConfig.Theme)
} else {
c.Set("theme", theme.Value)
}
}

func AdminThemeCheck(c *gin.Context) {
theme, err := c.Request.Cookie("theme")
if err != nil {
if strings.HasPrefix(module.GloablConfig.Theme, "mdui") {
c.Set("theme", module.GloablConfig.Theme)
} else {
c.Set("theme", "mdui")
}
} else {
if strings.HasPrefix(theme.Value, "mdui") {
c.Set("theme", theme.Value)
} else {
c.Set("theme", "mdui")
}
}
}

func LayoutCheck(c *gin.Context) {
layout, err := c.Request.Cookie("layout")
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func GetIcon(isFolder bool, fileType string) string {
fileKey = "exe"
}
}
return iconMap[config.Theme].(KV)[fileKey].(string)
return iconMap[GetCurrentTheme(config.Theme)].(KV)[fileKey].(string)
}
func GetBetweenStr(str, start, end string) string {
n := strings.Index(str, start)
Expand Down Expand Up @@ -734,3 +734,9 @@ func Md5Params(params map[string]string) string {
h.Write([]byte(signStr))
return hex.EncodeToString(h.Sum(nil))
}
func GetCurrentTheme(theme string) string {
if strings.HasPrefix(theme, "mdui") {
return "mdui"
}
return theme
}

0 comments on commit 78b23c8

Please sign in to comment.