💚 change build platform

This commit is contained in:
微凉 2021-11-04 13:23:17 +08:00
parent a7ecb7beb8
commit bfec01e837
8 changed files with 100 additions and 99 deletions

View File

@ -10,7 +10,7 @@ jobs:
build: build:
strategy: strategy:
matrix: matrix:
platform: [ubuntu-latest] platform: [macos-latest]
go-version: [1.17] go-version: [1.17]
name: Build name: Build
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
@ -42,7 +42,7 @@ jobs:
run: | run: |
docker pull techknowlogick/xgo:latest docker pull techknowlogick/xgo:latest
go install src.techknowlogick.com/xgo@latest go install src.techknowlogick.com/xgo@latest
sudo apt install upx sudo brew install upx
- name: Build web - name: Build web
run: | run: |

View File

@ -13,14 +13,6 @@ import (
"net/http" "net/http"
) )
var (
builtAt string
goVersion string
gitAuthor string
gitCommit string
gitTag string
)
func init() { func init() {
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file") 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")
@ -38,7 +30,7 @@ func Init() {
func main() { func main() {
if conf.Version { if conf.Version {
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion:%s\n", builtAt, goVersion, gitAuthor, gitCommit, gitTag) fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion:%s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
return return
} }
Init() Init()

View File

@ -5,7 +5,6 @@ import (
"github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/drivers"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/utils"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
@ -106,85 +105,79 @@ func initAccounts() {
func initSettings() { func initSettings() {
log.Infof("init settings...") log.Infof("init settings...")
version, err := model.GetSettingByKey("version") version := model.SettingItem{
if err != nil { Key: "version",
log.Debugf("first run") Value: conf.GitTag,
version = &model.SettingItem{ Description: "version",
Key: "version", Group: model.CONST,
Value: "0.0.0",
Type: "string",
Description: "version",
Group: model.CONST,
}
} }
settingsMap := map[string][]model.SettingItem{
"2.0.0": { _ = model.SaveSetting(version)
{
Key: "title", settings := []model.SettingItem{
Value: "Alist", {
Description: "title", Key: "title",
Type: "string", Value: "Alist",
Group: model.PUBLIC, Description: "title",
}, Group: model.PUBLIC,
{ },
Key: "password", {
Value: "alist", Key: "password",
Type: "string", Value: "alist",
Description: "password", Description: "password",
Group: model.PRIVATE, Group: model.PRIVATE,
}, },
{ {
Key: "version", Key: "logo",
Value: "2.0.0", Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Type: "string", Description: "logo",
Description: "version", Group: model.PUBLIC,
Group: model.CONST, },
}, {
{ Key: "favicon",
Key: "logo", Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", Description: "favicon",
Type: "string", Group: model.PUBLIC,
Description: "logo", },
Group: model.PUBLIC, {
}, Key: "icon color",
{ Value: "teal.300",
Key: "icon color", Description: "icon's color",
Value: "teal.300", Group: model.PUBLIC,
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",
{ Description: "text type extensions",
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", Key: "readme file",
Description: "text type extensions", Value: "hide",
}, Description: "hide readme file? (show/hide)",
{ },
Key: "readme file", {
Value: "hide", Key: "music cover",
Type: "string", Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
Description: "hide readme file? (show/hide)", Description: "music cover image",
}, Group: model.PUBLIC,
{ },
Key: "music cover", {
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", Key: "site beian",
Type: "string", Description: "chinese beian info",
Description: "music cover image", Group: model.PUBLIC,
}, },
{ {
Key: "site beian", Key: "home readme url",
Type: "string", Description: "when have multiple, the readme file to show",
Description: "chinese beian info", Group: model.PUBLIC,
},
}, },
} }
for k, v := range settingsMap { for _, v := range settings {
if utils.VersionCompare(k, version.Value) > 0 { _, err := model.GetSettingByKey(v.Key)
log.Infof("writing [v%s] settings", k) if err == gorm.ErrRecordNotFound {
err = model.SaveSettings(v) err = model.SaveSetting(v)
if err != nil { if err != nil {
log.Fatalf("save settings error") log.Fatalf("failed write setting: %s", err.Error())
} }
} }
} }

View File

@ -14,16 +14,20 @@ fi
ldflags="\ ldflags="\
-w -s \ -w -s \
-X 'main.builtAt=$builtAt' \ -X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
-X 'main.goVersion=$goVersion' \ -X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
-X 'main.gitAuthor=$gitAuthor' \ -X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
-X 'main.gitCommit=$gitCommit' \ -X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
-X 'main.gitTag=$gitTag' \ -X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
" "
cp -R ../alist-web/dist/* public cp -R ../alist-web/dist/* public
xgo -out alist -ldflags="$ldflags" . if [ "$1" == "release" ]; then
xgo -out alist -ldflags="$ldflags" .
else
xgo -targets=linux/amd64,windows/amd64,macos/amd64 -out alist -ldflags="$ldflags" .
fi
mkdir "build" mkdir "build"
mv alist-* build mv alist-* build
cd build || exit cd build || exit

View File

@ -7,6 +7,14 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
var (
BuiltAt string
GoVersion string
GitAuthor string
GitCommit string
GitTag string
)
var ( var (
ConfigFile string // config file ConfigFile string // config file
Conf *Config Conf *Config

View File

@ -115,8 +115,8 @@ func (o Onedrive) Items() []Item {
Required: true, Required: true,
}, },
{ {
Name: "site_url", Name: "site_id",
Label: "site url", Label: "site id",
Type: "string", Type: "string",
Required: false, Required: false,
}, },

View File

@ -7,7 +7,7 @@ import (
type Account struct { type Account struct {
Name string `json:"name" gorm:"primaryKey" validate:"required"` Name string `json:"name" gorm:"primaryKey" validate:"required"`
Index int `json:"index" validate:"required"` Index int `json:"index"`
Type string `json:"type"` Type string `json:"type"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
@ -28,8 +28,8 @@ type Account struct {
Zone string `json:"zone"` Zone string `json:"zone"`
RedirectUri string `json:"redirect_uri"` RedirectUri string `json:"redirect_uri"`
SiteUrl string `json:"site_url"` SiteUrl string `json:"site_url"`
SiteId string SiteId string `json:"site_id"`
OnedriveType string `json:"onedrive_type"` OnedriveType string `json:"onedrive_type"`
} }
var accountsMap = map[string]Account{} var accountsMap = map[string]Account{}

View File

@ -14,7 +14,7 @@ type SettingItem struct {
Key string `json:"key" gorm:"primaryKey" validate:"required"` Key string `json:"key" gorm:"primaryKey" validate:"required"`
Value string `json:"value"` Value string `json:"value"`
Description string `json:"description"` Description string `json:"description"`
Type string `json:"type"` //Type string `json:"type"`
Group int `json:"group"` Group int `json:"group"`
} }
@ -22,6 +22,10 @@ func SaveSettings(items []SettingItem) error {
return conf.DB.Save(items).Error return conf.DB.Save(items).Error
} }
func SaveSetting(item SettingItem) error {
return conf.DB.Save(item).Error
}
func GetSettingsPublic() (*[]SettingItem, error) { func GetSettingsPublic() (*[]SettingItem, error) {
var items []SettingItem var items []SettingItem
if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil { if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil {