build

pull/548/head
微凉 2021-11-03 19:51:19 +08:00
parent d78b64ee3c
commit 1f91e26730
5 changed files with 77 additions and 24 deletions

View File

@ -13,10 +13,22 @@ import (
"net/http"
)
func Init() {
var (
builtAt string
goVersion string
gitAuthor string
gitCommit string
gitTag string
)
func init() {
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file")
flag.BoolVar(&conf.Debug,"debug",false,"start with debug mode")
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.Parse()
}
func Init() {
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
@ -25,10 +37,14 @@ func Init() {
}
func main() {
if conf.Version {
log.Infof("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion:%s", builtAt, goVersion, gitAuthor, gitCommit, gitTag)
return
}
Init()
app := fiber.New()
server.InitApiRouter(app)
app.Use("/",filesystem.New(filesystem.Config{
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(public.Public),
NotFoundFile: "index.html",
}))

49
build.sh Normal file
View File

@ -0,0 +1,49 @@
#!/bin/bash
appName="alist"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
if [ "$1" == "release" ]; then
gitTag=$(git describe --abbrev=0 --tags)
else
gitTag="beta"
fi
ldflags="\
-w -s \
-X 'main.builtAt=$builtAt' \
-X 'main.goVersion=$goVersion' \
-X 'main.gitAuthor=$gitAuthor' \
-X 'main.gitCommit=$gitCommit' \
-X 'main.gitTag=$gitTag' \
"
cp -R ../alist-web/dist/* public
xgo -out alist -ldflags="$ldflags" .
mkdir "build"
mv alist-* build
cd build || exit
upx -9 ./*
find . -type f -print0 | xargs -0 md5sum > md5.txt
# compress file (release)
if [ "$1" == "release" ]; then
mkdir compress
mv md5.txt compress
for i in `find . -type f -name "$appName-linux-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-darwin-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-windows-*"`
do
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
done
fi

View File

@ -11,17 +11,18 @@ var (
ConfigFile string // config file
Conf *Config
Debug bool
Version bool
DB *gorm.DB
DB *gorm.DB
Cache *cache.Cache
Ctx = context.TODO()
Cron *cron.Cron
Ctx = context.TODO()
Cron *cron.Cron
)
var (
TextTypes = []string{"txt", "go", "md"}
OfficeTypes = []string{"doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"}
VideoTypes = []string{"mp4", "mkv", "avi", "mov", "rmvb"}
AudioTypes = []string{"mp3", "flac","ogg"}
ImageTypes = []string{"jpg","tiff","jpeg","png","gif","bmp","svg"}
AudioTypes = []string{"mp3", "flac", "ogg"}
ImageTypes = []string{"jpg", "tiff", "jpeg", "png", "gif", "bmp", "svg"}
)

View File

@ -22,9 +22,9 @@ func SaveSettings(items []SettingItem) error {
return conf.DB.Save(items).Error
}
func GetSettingsByGroup(t int) (*[]SettingItem, error) {
func GetSettingsPublic() (*[]SettingItem, error) {
var items []SettingItem
if err := conf.DB.Where("`group` = ?", t).Find(&items).Error; err != nil {
if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil {
return nil, err
}
return &items, nil

View File

@ -4,7 +4,6 @@ import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/model"
"github.com/gofiber/fiber/v2"
"strconv"
"strings"
)
@ -27,18 +26,6 @@ func SaveSettings(ctx *fiber.Ctx) error {
}
}
func GetSettingsByGroup(ctx *fiber.Ctx) error {
t, err := strconv.Atoi(ctx.Query("type"))
if err != nil {
return ErrorResp(ctx, err, 400)
}
settings, err := model.GetSettingsByGroup(t)
if err != nil {
return ErrorResp(ctx, err, 400)
}
return SuccessResp(ctx, settings)
}
func GetSettings(ctx *fiber.Ctx) error {
settings, err := model.GetSettings()
if err != nil {
@ -48,7 +35,7 @@ func GetSettings(ctx *fiber.Ctx) error {
}
func GetSettingsPublic(ctx *fiber.Ctx) error {
settings, err := model.GetSettingsByGroup(0)
settings, err := model.GetSettingsPublic()
if err != nil {
return ErrorResp(ctx, err, 400)
}