Skip to content

Commit

Permalink
✨ add customize style / script
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Nov 14, 2021
1 parent 0f93d2b commit 0dffb9a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
12 changes: 12 additions & 0 deletions bootstrap/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ func initSettings() {
Type: "bool",
Description: "check parent folder password",
},
{
Key: "customize style",
Value: "",
Type: "text",
Description: "customize style, don't need add <style></style>",
},
{
Key: "customize script",
Value: "",
Type: "text",
Description: "customize script, don't need add <script></script>",
},
}
for _, v := range settings {
_, err := model.GetSettingByKey(v.Key)
Expand Down
9 changes: 7 additions & 2 deletions conf/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ var (

// settings
var (
CheckParent bool
)
RawIndexHtml string
IndexHtml string
CheckParent bool
//CustomizeStyle string
//CustomizeScript string
//Favicon string
)
17 changes: 16 additions & 1 deletion model/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@ func LoadSettings() {
if err == nil {
conf.CheckParent = checkParent.Value == "true"
}
}
favicon, err := GetSettingByKey("favicon")
if err == nil {
//conf.Favicon = favicon.Value
conf.IndexHtml = strings.Replace(conf.RawIndexHtml, "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", favicon.Value, 1)
}
customizeStyle, err := GetSettingByKey("customize style")
if err == nil {
//conf.CustomizeStyle = customizeStyle.Value
conf.IndexHtml = strings.Replace(conf.IndexHtml, "/* customize-style */", customizeStyle.Value, 1)
}
customizeScript, err := GetSettingByKey("customize script")
if err == nil {
//conf.CustomizeStyle = customizeScript.Value
conf.IndexHtml = strings.Replace(conf.IndexHtml, "// customize-js", customizeScript.Value, 1)
}
}
7 changes: 4 additions & 3 deletions server/static.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/public"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
Expand All @@ -9,11 +10,11 @@ import (
"net/http"
)

var data []byte

func init() {
index, _ := public.Public.Open("index.html")
data, _ = ioutil.ReadAll(index)
data, _ := ioutil.ReadAll(index)
conf.RawIndexHtml = string(data)
}

func Static(r *gin.Engine) {
Expand All @@ -25,7 +26,7 @@ func Static(r *gin.Engine) {
r.NoRoute(func(c *gin.Context) {
c.Status(200)
c.Header("Content-Type", "text/html")
_, _ = c.Writer.Write(data)
_, _ = c.Writer.WriteString(conf.IndexHtml)
c.Writer.Flush()
})
}

0 comments on commit 0dffb9a

Please sign in to comment.