diff --git a/.gitignore b/.gitignore index 1698aa12..82c90ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ dist/ *.yml bin/* alist -*.json \ No newline at end of file +*.json +public/index.html +public/assets/ \ No newline at end of file diff --git a/alist.go b/alist.go index 48f0a6ca..4ac0421e 100644 --- a/alist.go +++ b/alist.go @@ -27,11 +27,14 @@ func Init() { func main() { Init() app := fiber.New() + server.InitApiRouter(app) app.Use("/",filesystem.New(filesystem.Config{ Root: http.FS(public.Public), - //NotFoundFile: "index.html", + NotFoundFile: "index.html", })) - server.InitApiRouter(app) log.Info("starting server") - _ = app.Listen(fmt.Sprintf(":%d", conf.Conf.Port)) + err := app.Listen(fmt.Sprintf(":%d", conf.Conf.Port)) + if err != nil { + log.Errorf("failed to start: %s", err.Error()) + } } diff --git a/bootstrap/model.go b/bootstrap/model.go index 7dcd0c53..43b88c22 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -135,18 +135,24 @@ func initSettings() { }, { Key: "logo", - Value: "", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", Type: "string", Description: "logo", Group: model.PUBLIC, }, { - Key: "icon_color", + Key: "icon color", Value: "blue.400", Type: "string", Description: "icon's color", Group: model.PUBLIC, }, + { + Key: "text types", + Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp", + Type: "string", + Description: "text type extensions", + }, }, } for k, v := range settingsMap { @@ -158,4 +164,8 @@ func initSettings() { } } } + textTypes, err := model.GetSettingByKey("text types") + if err==nil{ + conf.ImageTypes = strings.Split(textTypes.Value,",") + } } diff --git a/conf/var.go b/conf/var.go index 8e06fe6d..b8d504d9 100644 --- a/conf/var.go +++ b/conf/var.go @@ -23,5 +23,5 @@ var ( OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"} VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb"} AudioTypes = []string{"mp3", "flac","ogg"} - ImageTypes = []string{"jpg","jpeg","png","gif","bmp","svg"} + ImageTypes = []string{"jpg","tiff","jpeg","png","gif","bmp","svg"} ) diff --git a/server/router.go b/server/router.go index 38550384..7eb12776 100644 --- a/server/router.go +++ b/server/router.go @@ -17,7 +17,6 @@ func InitApiRouter(app *fiber.App) { api.Use(SetSuccess) public := api.Group("/public") { - // TODO check accounts public.Post("/path", CheckAccount, Path) public.Get("/settings", GetSettingsPublic) } diff --git a/server/setting.go b/server/setting.go index 7e4fbbc8..3b5aceb5 100644 --- a/server/setting.go +++ b/server/setting.go @@ -1,9 +1,11 @@ package server import ( + "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/model" "github.com/gofiber/fiber/v2" "strconv" + "strings" ) func SaveSettings(ctx *fiber.Ctx) error { @@ -17,6 +19,10 @@ func SaveSettings(ctx *fiber.Ctx) error { if err := model.SaveSettings(req); err != nil { return ErrorResp(ctx, err, 500) } else { + textTypes, err := model.GetSettingByKey("text types") + if err==nil{ + conf.ImageTypes = strings.Split(textTypes.Value,",") + } return SuccessResp(ctx) } } diff --git a/utils/file.go b/utils/file.go index f7c93281..61218059 100644 --- a/utils/file.go +++ b/utils/file.go @@ -34,7 +34,7 @@ func GetFileType(ext string) int { if ext == "" { return conf.UNKNOWN } - ext = strings.TrimLeft(ext,".") + ext = strings.ToLower(strings.TrimLeft(ext,".")) if IsContain(conf.OfficeTypes, ext) { return conf.OFFICE }