Skip to content

Commit

Permalink
✨ static files
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Oct 30, 2021
1 parent 2780efa commit eb358e6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ dist/
*.yml
bin/*
alist
*.json
*.json
public/index.html
public/assets/
9 changes: 6 additions & 3 deletions alist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
14 changes: 12 additions & 2 deletions bootstrap/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -158,4 +164,8 @@ func initSettings() {
}
}
}
textTypes, err := model.GetSettingByKey("text types")
if err==nil{
conf.ImageTypes = strings.Split(textTypes.Value,",")
}
}
2 changes: 1 addition & 1 deletion conf/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
)
1 change: 0 additions & 1 deletion server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions server/setting.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit eb358e6

Please sign in to comment.