Skip to content

Commit

Permalink
feat: Support for customizing account refresh time (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzylol authored Nov 13, 2024
1 parent f102494 commit a1fb099
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/server/wire/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
"claude": "http://localhost:9002",
"index": "http://localhost:9001",
"token": "https://token.oaifree.com"
}
},
"account_refresh_cron": ""
},
"security": {
"2fa_secret": "",
"admin_password": ""
"admin_password": "12345678"
},
"share": {
"custom": true,
Expand Down
15 changes: 12 additions & 3 deletions internal/server/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import (
"PandoraHelper/pkg/log"
"context"
"github.com/go-co-op/gocron"
"github.com/spf13/viper"
"go.uber.org/zap"
"time"
)

type Task struct {
conf *viper.Viper
log *log.Logger
scheduler *gocron.Scheduler
accountService service.AccountService
shareService service.ShareService
}

func NewTask(log *log.Logger, accountService service.AccountService, shareService service.ShareService) *Task {
func NewTask(conf *viper.Viper, log *log.Logger, accountService service.AccountService, shareService service.ShareService) *Task {
return &Task{
conf: conf,
log: log,
accountService: accountService,
shareService: shareService,
Expand Down Expand Up @@ -68,11 +71,17 @@ func (t *Task) Start(ctx context.Context) error {

t.scheduler = gocron.NewScheduler(time.UTC)

_, err := t.scheduler.Every(1).Day().At("00:00").Do(t.RefreshAllAccountEveryday, ctx)
var refreshCron = t.conf.GetString("pandora.account_refresh_cron")
t.log.Info("refresh cron with second is:" + refreshCron)
var err error
if refreshCron != "" {
_, err = t.scheduler.CronWithSeconds(refreshCron).Do(t.RefreshAllAccountEveryday, ctx)
} else {
_, err = t.scheduler.Every(1).Day().At("00:00").Do(t.RefreshAllAccountEveryday, ctx)
}
if err != nil {
return err
}

_, err = t.scheduler.Every(1).Day().At("00:05").Do(t.RefreshShareLimitEveryday, ctx)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func setDefaults(conf *viper.Viper) {
conf.SetDefault("pandora.domain.token", "https://token.oaifree.com")
conf.SetDefault("pandora.domain.index", "https://new.oaifree.com")
conf.SetDefault("pandora.domain.claude", "https://demo.fuclaude.com")
conf.SetDefault("pandora.account_refresh_cron", "")

// Share settings
conf.SetDefault("share.random", true)
Expand Down

0 comments on commit a1fb099

Please sign in to comment.