static files

pull/548/head
微凉 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
bin/*
alist
*.json
*.json
public/index.html
public/assets/

View File

@ -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())
}
}

View File

@ -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,",")
}
}

View File

@ -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"}
)

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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
}