static files

This commit is contained in:
微凉 2021-10-30 19:26:23 +08:00
parent 2780efaea8
commit eb358e6ede
7 changed files with 29 additions and 9 deletions

4
.gitignore vendored
View File

@ -23,4 +23,6 @@ dist/
*.yml *.yml
bin/* bin/*
alist alist
*.json *.json
public/index.html
public/assets/

View File

@ -27,11 +27,14 @@ func Init() {
func main() { func main() {
Init() Init()
app := fiber.New() app := fiber.New()
server.InitApiRouter(app)
app.Use("/",filesystem.New(filesystem.Config{ app.Use("/",filesystem.New(filesystem.Config{
Root: http.FS(public.Public), Root: http.FS(public.Public),
//NotFoundFile: "index.html", NotFoundFile: "index.html",
})) }))
server.InitApiRouter(app)
log.Info("starting server") 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())
}
} }

View File

@ -135,18 +135,24 @@ func initSettings() {
}, },
{ {
Key: "logo", Key: "logo",
Value: "", Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Type: "string", Type: "string",
Description: "logo", Description: "logo",
Group: model.PUBLIC, Group: model.PUBLIC,
}, },
{ {
Key: "icon_color", Key: "icon color",
Value: "blue.400", Value: "blue.400",
Type: "string", Type: "string",
Description: "icon's color", Description: "icon's color",
Group: model.PUBLIC, 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 { 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,",")
}
} }

View File

@ -23,5 +23,5 @@ var (
OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"} OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"}
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb"} VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb"}
AudioTypes = []string{"mp3", "flac","ogg"} AudioTypes = []string{"mp3", "flac","ogg"}
ImageTypes = []string{"jpg","jpeg","png","gif","bmp","svg"} ImageTypes = []string{"jpg","tiff","jpeg","png","gif","bmp","svg"}
) )

View File

@ -17,7 +17,6 @@ func InitApiRouter(app *fiber.App) {
api.Use(SetSuccess) api.Use(SetSuccess)
public := api.Group("/public") public := api.Group("/public")
{ {
// TODO check accounts
public.Post("/path", CheckAccount, Path) public.Post("/path", CheckAccount, Path)
public.Get("/settings", GetSettingsPublic) public.Get("/settings", GetSettingsPublic)
} }

View File

@ -1,9 +1,11 @@
package server package server
import ( import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"strconv" "strconv"
"strings"
) )
func SaveSettings(ctx *fiber.Ctx) error { func SaveSettings(ctx *fiber.Ctx) error {
@ -17,6 +19,10 @@ func SaveSettings(ctx *fiber.Ctx) error {
if err := model.SaveSettings(req); err != nil { if err := model.SaveSettings(req); err != nil {
return ErrorResp(ctx, err, 500) return ErrorResp(ctx, err, 500)
} else { } else {
textTypes, err := model.GetSettingByKey("text types")
if err==nil{
conf.ImageTypes = strings.Split(textTypes.Value,",")
}
return SuccessResp(ctx) return SuccessResp(ctx)
} }
} }

View File

@ -34,7 +34,7 @@ func GetFileType(ext string) int {
if ext == "" { if ext == "" {
return conf.UNKNOWN return conf.UNKNOWN
} }
ext = strings.TrimLeft(ext,".") ext = strings.ToLower(strings.TrimLeft(ext,"."))
if IsContain(conf.OfficeTypes, ext) { if IsContain(conf.OfficeTypes, ext) {
return conf.OFFICE return conf.OFFICE
} }