💚 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:
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: |

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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