Skip to content

Commit a1fb099

Browse files
authored
feat: Support for customizing account refresh time (#143)
1 parent f102494 commit a1fb099

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

cmd/server/wire/wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
"claude": "http://localhost:9002",
4747
"index": "http://localhost:9001",
4848
"token": "https://token.oaifree.com"
49-
}
49+
},
50+
"account_refresh_cron": ""
5051
},
5152
"security": {
5253
"2fa_secret": "",
53-
"admin_password": ""
54+
"admin_password": "12345678"
5455
},
5556
"share": {
5657
"custom": true,

internal/server/task.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import (
55
"PandoraHelper/pkg/log"
66
"context"
77
"github.com/go-co-op/gocron"
8+
"github.com/spf13/viper"
89
"go.uber.org/zap"
910
"time"
1011
)
1112

1213
type Task struct {
14+
conf *viper.Viper
1315
log *log.Logger
1416
scheduler *gocron.Scheduler
1517
accountService service.AccountService
1618
shareService service.ShareService
1719
}
1820

19-
func NewTask(log *log.Logger, accountService service.AccountService, shareService service.ShareService) *Task {
21+
func NewTask(conf *viper.Viper, log *log.Logger, accountService service.AccountService, shareService service.ShareService) *Task {
2022
return &Task{
23+
conf: conf,
2124
log: log,
2225
accountService: accountService,
2326
shareService: shareService,
@@ -68,11 +71,17 @@ func (t *Task) Start(ctx context.Context) error {
6871

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

71-
_, err := t.scheduler.Every(1).Day().At("00:00").Do(t.RefreshAllAccountEveryday, ctx)
74+
var refreshCron = t.conf.GetString("pandora.account_refresh_cron")
75+
t.log.Info("refresh cron with second is:" + refreshCron)
76+
var err error
77+
if refreshCron != "" {
78+
_, err = t.scheduler.CronWithSeconds(refreshCron).Do(t.RefreshAllAccountEveryday, ctx)
79+
} else {
80+
_, err = t.scheduler.Every(1).Day().At("00:00").Do(t.RefreshAllAccountEveryday, ctx)
81+
}
7282
if err != nil {
7383
return err
7484
}
75-
7685
_, err = t.scheduler.Every(1).Day().At("00:05").Do(t.RefreshShareLimitEveryday, ctx)
7786
if err != nil {
7887
return err

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func setDefaults(conf *viper.Viper) {
5353
conf.SetDefault("pandora.domain.token", "https://token.oaifree.com")
5454
conf.SetDefault("pandora.domain.index", "https://new.oaifree.com")
5555
conf.SetDefault("pandora.domain.claude", "https://demo.fuclaude.com")
56+
conf.SetDefault("pandora.account_refresh_cron", "")
5657

5758
// Share settings
5859
conf.SetDefault("share.random", true)

0 commit comments

Comments
 (0)