diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 24846b4..8e123e2 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -63,9 +63,9 @@ jobs: README.md ldflags: >- -s -w - -X "github.com/krau/SaveAny-Bot/pkg/consts.Version=${{ env.VERSION }}" - -X "github.com/krau/SaveAny-Bot/pkg/consts.BuildTime=${{ format(github.event.repository.updated_at, 'yyyy-MM-dd HH:mm:ss') }}" - -X "github.com/krau/SaveAny-Bot/pkg/consts.GitCommit=${{ github.sha }}" + -X "github.com/krau/SaveAny-Bot/config.Version=${{ env.VERSION }}" + -X "github.com/krau/SaveAny-Bot/config.BuildTime=${{ format(github.event.repository.updated_at, 'yyyy-MM-dd HH:mm:ss') }}" + -X "github.com/krau/SaveAny-Bot/config.GitCommit=${{ github.sha }}" binary_name: saveany-bot env: VERSION: ${{ env.VERSION }} diff --git a/Dockerfile b/Dockerfile index 86c97fc..a7ea018 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,9 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ go build -trimpath \ -ldflags=" \ -s -w \ - -X 'github.com/krau/SaveAny-Bot/common.Version=${VERSION}' \ - -X 'github.com/krau/SaveAny-Bot/common.GitCommit=${GitCommit}' \ - -X 'github.com/krau/SaveAny-Bot/common.BuildTime=${BuildTime}' \ + -X 'github.com/krau/SaveAny-Bot/config.Version=${VERSION}' \ + -X 'github.com/krau/SaveAny-Bot/config.GitCommit=${GitCommit}' \ + -X 'github.com/krau/SaveAny-Bot/config.BuildTime=${BuildTime}' \ " \ -o saveany-bot . diff --git a/client/bot/handlers/help.go b/client/bot/handlers/help.go index 21f6455..9e975d4 100644 --- a/client/bot/handlers/help.go +++ b/client/bot/handlers/help.go @@ -5,7 +5,7 @@ import ( "github.com/celestix/gotgproto/dispatcher" "github.com/celestix/gotgproto/ext" - "github.com/krau/SaveAny-Bot/pkg/consts" + "github.com/krau/SaveAny-Bot/config" ) func handleHelpCmd(ctx *ext.Context, update *ext.Update) error { @@ -24,10 +24,10 @@ Save Any Bot - 转存你的 Telegram 文件 使用帮助: https://sabot.unv.app/usage/ ` - shortHash := consts.GitCommit + shortHash := config.GitCommit if len(shortHash) > 7 { shortHash = shortHash[:7] } - ctx.Reply(update, ext.ReplyTextString(fmt.Sprintf(helpText, consts.Version, shortHash)), nil) + ctx.Reply(update, ext.ReplyTextString(fmt.Sprintf(helpText, config.Version, shortHash)), nil) return dispatcher.EndGroups } diff --git a/cmd/version.go b/cmd/version.go index 4061093..456925a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -4,7 +4,7 @@ import ( "fmt" "runtime" - "github.com/krau/SaveAny-Bot/pkg/consts" + "github.com/krau/SaveAny-Bot/config" "github.com/rhysd/go-github-selfupdate/selfupdate" "github.com/blang/semver" @@ -16,7 +16,7 @@ var VersionCmd = &cobra.Command{ Aliases: []string{"v"}, Short: "Print the version number of saveany-bot", Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("saveany-bot version: %s %s/%s\nBuildTime: %s, Commit: %s\n", consts.Version, runtime.GOOS, runtime.GOARCH, consts.BuildTime, consts.GitCommit) + fmt.Printf("saveany-bot version: %s %s/%s\nBuildTime: %s, Commit: %s\n", config.Version, runtime.GOOS, runtime.GOARCH, config.BuildTime, config.GitCommit) }, } @@ -25,14 +25,14 @@ var upgradeCmd = &cobra.Command{ Aliases: []string{"up"}, Short: "Upgrade saveany-bot to the latest version", Run: func(cmd *cobra.Command, args []string) { - v := semver.MustParse(consts.Version) + v := semver.MustParse(config.Version) latest, err := selfupdate.UpdateSelf(v, "krau/SaveAny-Bot") if err != nil { fmt.Println("Binary update failed:", err) return } if latest.Version.Equals(v) { - fmt.Println("Current binary is the latest version", consts.Version) + fmt.Println("Current binary is the latest version", config.Version) } else { fmt.Println("Successfully updated to version", latest.Version) fmt.Println("Release note:\n", latest.ReleaseNotes) diff --git a/pkg/consts/version.go b/config/version.go similarity index 54% rename from pkg/consts/version.go rename to config/version.go index 9dc5fe5..7335358 100644 --- a/pkg/consts/version.go +++ b/config/version.go @@ -1,7 +1,7 @@ -package consts +package config // inject version by '-X' flag -// go build -ldflags "-X github.com/krau/SaveAny-Bot/pkg/consts.Version=${{ env.VERSION }}" +// go build -ldflags "-X github.com/krau/SaveAny-Bot/config.Version=${{ env.VERSION }}" var ( Version string = "dev" BuildTime string = "unknown" diff --git a/database/model.go b/database/model.go index 22c153a..7a3b879 100644 --- a/database/model.go +++ b/database/model.go @@ -6,13 +6,14 @@ import ( type User struct { gorm.Model - ChatID int64 `gorm:"uniqueIndex;not null"` - Silent bool - DefaultStorage string - Dirs []Dir - ApplyRule bool - Rules []Rule - WatchChats []WatchChat + ChatID int64 `gorm:"uniqueIndex;not null"` + Silent bool + DefaultStorage string + Dirs []Dir + ApplyRule bool + Rules []Rule + WatchChats []WatchChat + FilenameStrategy string } type WatchChat struct {