From 0dffb9aaa1ec9dda388da8a3d906ec7b5abc04c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com>
Date: Sun, 14 Nov 2021 14:37:26 +0800
Subject: [PATCH] :sparkles: add customize style / script
---
bootstrap/model.go | 12 ++++++++++++
conf/var.go | 9 +++++++--
model/setting.go | 17 ++++++++++++++++-
server/static.go | 7 ++++---
4 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/bootstrap/model.go b/bootstrap/model.go
index 9d940694..e72b4062 100644
--- a/bootstrap/model.go
+++ b/bootstrap/model.go
@@ -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 ",
+ },
+ {
+ Key: "customize script",
+ Value: "",
+ Type: "text",
+ Description: "customize script, don't need add ",
+ },
}
for _, v := range settings {
_, err := model.GetSettingByKey(v.Key)
diff --git a/conf/var.go b/conf/var.go
index f66bd1bf..2192491d 100644
--- a/conf/var.go
+++ b/conf/var.go
@@ -37,5 +37,10 @@ var (
// settings
var (
- CheckParent bool
-)
\ No newline at end of file
+ RawIndexHtml string
+ IndexHtml string
+ CheckParent bool
+ //CustomizeStyle string
+ //CustomizeScript string
+ //Favicon string
+)
diff --git a/model/setting.go b/model/setting.go
index a8abd37f..e1c92a21 100644
--- a/model/setting.go
+++ b/model/setting.go
@@ -61,4 +61,19 @@ func LoadSettings() {
if err == nil {
conf.CheckParent = checkParent.Value == "true"
}
-}
\ No newline at end of file
+ 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)
+ }
+}
diff --git a/server/static.go b/server/static.go
index 9059b78f..8d01c250 100644
--- a/server/static.go
+++ b/server/static.go
@@ -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"
@@ -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) {
@@ -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()
})
}