From bfec01e83756b1e4aa849621453274cb26ab30cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Thu, 4 Nov 2021 13:23:17 +0800 Subject: [PATCH] :green_heart: change build platform --- .github/workflows/build.yml | 4 +- alist.go | 10 +-- bootstrap/model.go | 145 +++++++++++++++++------------------- build.sh | 16 ++-- conf/var.go | 8 ++ drivers/onedrive.go | 4 +- model/account.go | 6 +- model/setting.go | 6 +- 8 files changed, 100 insertions(+), 99 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8323c6c..6f110e68 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - platform: [ubuntu-latest] + platform: [macos-latest] go-version: [1.17] name: Build runs-on: ${{ matrix.platform }} @@ -42,7 +42,7 @@ jobs: run: | docker pull techknowlogick/xgo:latest go install src.techknowlogick.com/xgo@latest - sudo apt install upx + sudo brew install upx - name: Build web run: | diff --git a/alist.go b/alist.go index 3d748192..f0936cbb 100644 --- a/alist.go +++ b/alist.go @@ -13,14 +13,6 @@ import ( "net/http" ) -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") @@ -38,7 +30,7 @@ func Init() { func main() { 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 } Init() diff --git a/bootstrap/model.go b/bootstrap/model.go index aa009b04..3ec622b0 100644 --- a/bootstrap/model.go +++ b/bootstrap/model.go @@ -5,7 +5,6 @@ import ( "github.com/Xhofe/alist/conf" "github.com/Xhofe/alist/drivers" "github.com/Xhofe/alist/model" - "github.com/Xhofe/alist/utils" log "github.com/sirupsen/logrus" "gorm.io/driver/mysql" "gorm.io/driver/postgres" @@ -106,85 +105,79 @@ func initAccounts() { func initSettings() { log.Infof("init settings...") - version, err := model.GetSettingByKey("version") - if err != nil { - log.Debugf("first run") - version = &model.SettingItem{ - Key: "version", - Value: "0.0.0", - Type: "string", - Description: "version", - Group: model.CONST, - } + version := model.SettingItem{ + Key: "version", + Value: conf.GitTag, + Description: "version", + Group: model.CONST, } - settingsMap := map[string][]model.SettingItem{ - "2.0.0": { - { - Key: "title", - Value: "Alist", - Description: "title", - Type: "string", - Group: model.PUBLIC, - }, - { - Key: "password", - Value: "alist", - Type: "string", - Description: "password", - Group: model.PRIVATE, - }, - { - Key: "version", - Value: "2.0.0", - Type: "string", - Description: "version", - Group: model.CONST, - }, - { - Key: "logo", - Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", - Type: "string", - Description: "logo", - Group: model.PUBLIC, - }, - { - Key: "icon color", - Value: "teal.300", - 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", - }, - { - Key: "readme file", - Value: "hide", - Type: "string", - Description: "hide readme file? (show/hide)", - }, - { - Key: "music cover", - Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", - Type: "string", - Description: "music cover image", - }, - { - Key: "site beian", - Type: "string", - Description: "chinese beian info", - }, + + _ = model.SaveSetting(version) + + settings := []model.SettingItem{ + { + Key: "title", + Value: "Alist", + Description: "title", + Group: model.PUBLIC, + }, + { + Key: "password", + Value: "alist", + Description: "password", + Group: model.PRIVATE, + }, + { + Key: "logo", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "logo", + Group: model.PUBLIC, + }, + { + Key: "favicon", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "favicon", + Group: model.PUBLIC, + }, + { + Key: "icon color", + Value: "teal.300", + 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: "readme file", + Value: "hide", + Description: "hide readme file? (show/hide)", + }, + { + Key: "music cover", + Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png", + Description: "music cover image", + Group: model.PUBLIC, + }, + { + Key: "site beian", + Description: "chinese beian info", + Group: model.PUBLIC, + }, + { + Key: "home readme url", + Description: "when have multiple, the readme file to show", + Group: model.PUBLIC, }, } - for k, v := range settingsMap { - if utils.VersionCompare(k, version.Value) > 0 { - log.Infof("writing [v%s] settings", k) - err = model.SaveSettings(v) + for _, v := range settings { + _, err := model.GetSettingByKey(v.Key) + if err == gorm.ErrRecordNotFound { + err = model.SaveSetting(v) if err != nil { - log.Fatalf("save settings error") + log.Fatalf("failed write setting: %s", err.Error()) } } } diff --git a/build.sh b/build.sh index 486ef467..fe72264c 100644 --- a/build.sh +++ b/build.sh @@ -14,16 +14,20 @@ fi ldflags="\ -w -s \ --X 'main.builtAt=$builtAt' \ --X 'main.goVersion=$goVersion' \ --X 'main.gitAuthor=$gitAuthor' \ --X 'main.gitCommit=$gitCommit' \ --X 'main.gitTag=$gitTag' \ +-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ +-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \ +-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \ +-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \ +-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \ " 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" mv alist-* build cd build || exit diff --git a/conf/var.go b/conf/var.go index 532fe1a6..afe1e72d 100644 --- a/conf/var.go +++ b/conf/var.go @@ -7,6 +7,14 @@ import ( "gorm.io/gorm" ) +var ( + BuiltAt string + GoVersion string + GitAuthor string + GitCommit string + GitTag string +) + var ( ConfigFile string // config file Conf *Config diff --git a/drivers/onedrive.go b/drivers/onedrive.go index 6513def1..3a2fbf07 100644 --- a/drivers/onedrive.go +++ b/drivers/onedrive.go @@ -115,8 +115,8 @@ func (o Onedrive) Items() []Item { Required: true, }, { - Name: "site_url", - Label: "site url", + Name: "site_id", + Label: "site id", Type: "string", Required: false, }, diff --git a/model/account.go b/model/account.go index 25bb105b..72a080fa 100644 --- a/model/account.go +++ b/model/account.go @@ -7,7 +7,7 @@ import ( type Account struct { Name string `json:"name" gorm:"primaryKey" validate:"required"` - Index int `json:"index" validate:"required"` + Index int `json:"index"` Type string `json:"type"` Username string `json:"username"` Password string `json:"password"` @@ -28,8 +28,8 @@ type Account struct { Zone string `json:"zone"` RedirectUri string `json:"redirect_uri"` SiteUrl string `json:"site_url"` - SiteId string - OnedriveType string `json:"onedrive_type"` + SiteId string `json:"site_id"` + OnedriveType string `json:"onedrive_type"` } var accountsMap = map[string]Account{} diff --git a/model/setting.go b/model/setting.go index c21a0f5c..80805e8e 100644 --- a/model/setting.go +++ b/model/setting.go @@ -14,7 +14,7 @@ type SettingItem struct { Key string `json:"key" gorm:"primaryKey" validate:"required"` Value string `json:"value"` Description string `json:"description"` - Type string `json:"type"` + //Type string `json:"type"` Group int `json:"group"` } @@ -22,6 +22,10 @@ func SaveSettings(items []SettingItem) error { return conf.DB.Save(items).Error } +func SaveSetting(item SettingItem) error { + return conf.DB.Save(item).Error +} + func GetSettingsPublic() (*[]SettingItem, error) { var items []SettingItem if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil {