Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
6b0cf466
Unverified
Commit
6b0cf466
authored
Apr 23, 2026
by
Wesley Liddick
Committed by
GitHub
Apr 23, 2026
Browse files
Merge pull request #1815 from james-6-23/feat_rpm
feat(rpm): RPM 限流模块优化
parents
ef967d8f
dc5d42ad
Changes
79
Hide whitespace changes
Inline
Side-by-side
backend/cmd/server/wire_gen.go
View file @
6b0cf466
...
...
@@ -61,8 +61,9 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
billingCache
:=
repository
.
NewBillingCache
(
redisClient
)
userSubscriptionRepository
:=
repository
.
NewUserSubscriptionRepository
(
client
)
apiKeyRepository
:=
repository
.
NewAPIKeyRepository
(
client
,
db
)
billingCacheService
:=
service
.
NewBillingCacheService
(
billingCache
,
userRepository
,
userSubscriptionRepository
,
apiKeyRepository
,
configConfig
)
userRPMCache
:=
repository
.
NewUserRPMCache
(
redisClient
)
userGroupRateRepository
:=
repository
.
NewUserGroupRateRepository
(
db
)
billingCacheService
:=
service
.
ProvideBillingCacheService
(
billingCache
,
userRepository
,
userSubscriptionRepository
,
apiKeyRepository
,
userRPMCache
,
userGroupRateRepository
,
configConfig
)
apiKeyCache
:=
repository
.
NewAPIKeyCache
(
redisClient
)
apiKeyService
:=
service
.
NewAPIKeyService
(
apiKeyRepository
,
userRepository
,
groupRepository
,
userSubscriptionRepository
,
userGroupRateRepository
,
apiKeyCache
,
configConfig
)
apiKeyAuthCacheInvalidator
:=
service
.
ProvideAPIKeyAuthCacheInvalidator
(
apiKeyService
)
...
...
@@ -104,7 +105,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
proxyExitInfoProber
:=
repository
.
NewProxyExitInfoProber
(
configConfig
)
proxyLatencyCache
:=
repository
.
NewProxyLatencyCache
(
redisClient
)
privacyClientFactory
:=
providePrivacyClientFactory
()
adminService
:=
service
.
NewAdminService
(
userRepository
,
groupRepository
,
accountRepository
,
proxyRepository
,
apiKeyRepository
,
redeemCodeRepository
,
userGroupRateRepository
,
billingCacheService
,
proxyExitInfoProber
,
proxyLatencyCache
,
apiKeyAuthCacheInvalidator
,
client
,
settingService
,
subscriptionService
,
userSubscriptionRepository
,
privacyClientFactory
)
adminService
:=
service
.
NewAdminService
(
userRepository
,
groupRepository
,
accountRepository
,
proxyRepository
,
apiKeyRepository
,
redeemCodeRepository
,
userGroupRateRepository
,
userRPMCache
,
billingCacheService
,
proxyExitInfoProber
,
proxyLatencyCache
,
apiKeyAuthCacheInvalidator
,
client
,
settingService
,
subscriptionService
,
userSubscriptionRepository
,
privacyClientFactory
)
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyService
:=
service
.
ProvideConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
adminUserHandler
:=
admin
.
NewUserHandler
(
adminService
,
concurrencyService
)
...
...
@@ -137,7 +138,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
tlsFingerprintProfileCache
:=
repository
.
NewTLSFingerprintProfileCache
(
redisClient
)
tlsFingerprintProfileService
:=
service
.
NewTLSFingerprintProfileService
(
tlsFingerprintProfileRepository
,
tlsFingerprintProfileCache
)
accountUsageService
:=
service
.
NewAccountUsageService
(
accountRepository
,
usageLogRepository
,
claudeUsageFetcher
,
geminiQuotaService
,
antigravityQuotaFetcher
,
usageCache
,
identityCache
,
tlsFingerprintProfileService
)
oAuthRefreshAPI
:=
service
.
New
OAuthRefreshAPI
(
accountRepository
,
geminiTokenCache
)
oAuthRefreshAPI
:=
service
.
Provide
OAuthRefreshAPI
(
accountRepository
,
geminiTokenCache
)
geminiTokenProvider
:=
service
.
ProvideGeminiTokenProvider
(
accountRepository
,
geminiTokenCache
,
geminiOAuthService
,
oAuthRefreshAPI
)
gatewayCache
:=
repository
.
NewGatewayCache
(
redisClient
)
schedulerOutboxRepository
:=
repository
.
NewSchedulerOutboxRepository
(
db
)
...
...
@@ -184,6 +185,15 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
geminiMessagesCompatService
:=
service
.
NewGeminiMessagesCompatService
(
accountRepository
,
groupRepository
,
gatewayCache
,
schedulerSnapshotService
,
geminiTokenProvider
,
rateLimitService
,
httpUpstream
,
antigravityGatewayService
,
configConfig
)
opsSystemLogSink
:=
service
.
ProvideOpsSystemLogSink
(
opsRepository
)
opsService
:=
service
.
NewOpsService
(
opsRepository
,
settingRepository
,
configConfig
,
accountRepository
,
userRepository
,
concurrencyService
,
gatewayService
,
openAIGatewayService
,
geminiMessagesCompatService
,
antigravityGatewayService
,
opsSystemLogSink
)
encryptionKey
,
err
:=
payment
.
ProvideEncryptionKey
(
configConfig
)
if
err
!=
nil
{
return
nil
,
err
}
paymentConfigService
:=
service
.
ProvidePaymentConfigService
(
client
,
settingRepository
,
encryptionKey
)
registry
:=
payment
.
ProvideRegistry
()
defaultLoadBalancer
:=
payment
.
ProvideDefaultLoadBalancer
(
client
,
encryptionKey
)
paymentService
:=
service
.
NewPaymentService
(
client
,
registry
,
defaultLoadBalancer
,
redeemService
,
subscriptionService
,
paymentConfigService
,
userRepository
,
groupRepository
)
settingHandler
:=
admin
.
NewSettingHandler
(
settingService
,
emailService
,
turnstileService
,
opsService
,
paymentConfigService
,
paymentService
)
opsHandler
:=
admin
.
NewOpsHandler
(
opsService
)
updateCache
:=
repository
.
NewUpdateCache
(
redisClient
)
gitHubReleaseClient
:=
repository
.
ProvideGitHubReleaseClient
(
configConfig
)
...
...
@@ -211,16 +221,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
scheduledTestService
:=
service
.
ProvideScheduledTestService
(
scheduledTestPlanRepository
,
scheduledTestResultRepository
)
scheduledTestHandler
:=
admin
.
NewScheduledTestHandler
(
scheduledTestService
)
channelHandler
:=
admin
.
NewChannelHandler
(
channelService
,
billingService
)
registry
:=
payment
.
ProvideRegistry
()
encryptionKey
,
err
:=
payment
.
ProvideEncryptionKey
(
configConfig
)
if
err
!=
nil
{
return
nil
,
err
}
defaultLoadBalancer
:=
payment
.
ProvideDefaultLoadBalancer
(
client
,
encryptionKey
)
paymentConfigService
:=
service
.
ProvidePaymentConfigService
(
client
,
settingRepository
,
encryptionKey
)
paymentService
:=
service
.
NewPaymentService
(
client
,
registry
,
defaultLoadBalancer
,
redeemService
,
subscriptionService
,
paymentConfigService
,
userRepository
,
groupRepository
)
settingHandler
:=
admin
.
NewSettingHandler
(
settingService
,
emailService
,
turnstileService
,
opsService
,
paymentConfigService
,
paymentService
)
paymentOrderExpiryService
:=
service
.
ProvidePaymentOrderExpiryService
(
paymentService
)
paymentHandler
:=
admin
.
NewPaymentHandler
(
paymentService
,
paymentConfigService
)
adminHandlers
:=
handler
.
ProvideAdminHandlers
(
dashboardHandler
,
adminUserHandler
,
groupHandler
,
accountHandler
,
adminAnnouncementHandler
,
dataManagementHandler
,
backupHandler
,
oAuthHandler
,
openAIOAuthHandler
,
geminiOAuthHandler
,
antigravityOAuthHandler
,
proxyHandler
,
adminRedeemHandler
,
promoHandler
,
settingHandler
,
opsHandler
,
systemHandler
,
adminSubscriptionHandler
,
adminUsageHandler
,
userAttributeHandler
,
errorPassthroughHandler
,
tlsFingerprintProfileHandler
,
adminAPIKeyHandler
,
scheduledTestHandler
,
channelHandler
,
paymentHandler
)
usageRecordWorkerPool
:=
service
.
NewUsageRecordWorkerPool
(
configConfig
)
...
...
@@ -249,6 +249,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
accountExpiryService
:=
service
.
ProvideAccountExpiryService
(
accountRepository
)
subscriptionExpiryService
:=
service
.
ProvideSubscriptionExpiryService
(
userSubscriptionRepository
)
scheduledTestRunnerService
:=
service
.
ProvideScheduledTestRunnerService
(
scheduledTestPlanRepository
,
scheduledTestService
,
accountTestService
,
rateLimitService
,
configConfig
)
paymentOrderExpiryService
:=
service
.
ProvidePaymentOrderExpiryService
(
paymentService
)
v
:=
provideCleanup
(
client
,
redisClient
,
opsMetricsCollector
,
opsAggregationService
,
opsAlertEvaluatorService
,
opsCleanupService
,
opsScheduledReportService
,
opsSystemLogSink
,
schedulerSnapshotService
,
tokenRefreshService
,
accountExpiryService
,
subscriptionExpiryService
,
usageCleanupService
,
idempotencyCleanupService
,
pricingService
,
emailQueueService
,
billingCacheService
,
usageRecordWorkerPool
,
subscriptionService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
openAIGatewayService
,
scheduledTestRunnerService
,
backupService
,
paymentOrderExpiryService
)
application
:=
&
Application
{
Server
:
httpServer
,
...
...
backend/cmd/server/wire_gen_test.go
View file @
6b0cf466
...
...
@@ -43,7 +43,7 @@ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
subscriptionExpirySvc
:=
service
.
NewSubscriptionExpiryService
(
nil
,
time
.
Second
)
pricingSvc
:=
service
.
NewPricingService
(
cfg
,
nil
)
emailQueueSvc
:=
service
.
NewEmailQueueService
(
nil
,
1
)
billingCacheSvc
:=
service
.
NewBillingCacheService
(
nil
,
nil
,
nil
,
nil
,
cfg
)
billingCacheSvc
:=
service
.
NewBillingCacheService
(
nil
,
nil
,
nil
,
nil
,
nil
,
nil
,
cfg
)
idempotencyCleanupSvc
:=
service
.
NewIdempotencyCleanupService
(
nil
,
cfg
)
schedulerSnapshotSvc
:=
service
.
NewSchedulerSnapshotService
(
nil
,
nil
,
nil
,
nil
,
cfg
)
opsSystemLogSinkSvc
:=
service
.
NewOpsSystemLogSink
(
nil
)
...
...
backend/ent/group.go
View file @
6b0cf466
...
...
@@ -79,6 +79,8 @@ type Group struct {
DefaultMappedModel
string
`json:"default_mapped_model,omitempty"`
// OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型
MessagesDispatchModelConfig
domain
.
OpenAIMessagesDispatchModelConfig
`json:"messages_dispatch_model_config,omitempty"`
// 分组 RPM 上限,0 表示不限制;设置后接管该分组用户的限流
RpmLimit
int
`json:"rpm_limit,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the GroupQuery when eager-loading is set.
Edges
GroupEdges
`json:"edges"`
...
...
@@ -191,7 +193,7 @@ func (*Group) scanValues(columns []string) ([]any, error) {
values
[
i
]
=
new
(
sql
.
NullBool
)
case
group
.
FieldRateMultiplier
,
group
.
FieldDailyLimitUsd
,
group
.
FieldWeeklyLimitUsd
,
group
.
FieldMonthlyLimitUsd
,
group
.
FieldImagePrice1k
,
group
.
FieldImagePrice2k
,
group
.
FieldImagePrice4k
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
group
.
FieldID
,
group
.
FieldDefaultValidityDays
,
group
.
FieldFallbackGroupID
,
group
.
FieldFallbackGroupIDOnInvalidRequest
,
group
.
FieldSortOrder
:
case
group
.
FieldID
,
group
.
FieldDefaultValidityDays
,
group
.
FieldFallbackGroupID
,
group
.
FieldFallbackGroupIDOnInvalidRequest
,
group
.
FieldSortOrder
,
group
.
FieldRpmLimit
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
group
.
FieldName
,
group
.
FieldDescription
,
group
.
FieldStatus
,
group
.
FieldPlatform
,
group
.
FieldSubscriptionType
,
group
.
FieldDefaultMappedModel
:
values
[
i
]
=
new
(
sql
.
NullString
)
...
...
@@ -414,6 +416,12 @@ func (_m *Group) assignValues(columns []string, values []any) error {
return
fmt
.
Errorf
(
"unmarshal field messages_dispatch_model_config: %w"
,
err
)
}
}
case
group
.
FieldRpmLimit
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field rpm_limit"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
RpmLimit
=
int
(
value
.
Int64
)
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
...
...
@@ -599,6 +607,9 @@ func (_m *Group) String() string {
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"messages_dispatch_model_config="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
MessagesDispatchModelConfig
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"rpm_limit="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
RpmLimit
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
...
...
backend/ent/group/group.go
View file @
6b0cf466
...
...
@@ -76,6 +76,8 @@ const (
FieldDefaultMappedModel
=
"default_mapped_model"
// FieldMessagesDispatchModelConfig holds the string denoting the messages_dispatch_model_config field in the database.
FieldMessagesDispatchModelConfig
=
"messages_dispatch_model_config"
// FieldRpmLimit holds the string denoting the rpm_limit field in the database.
FieldRpmLimit
=
"rpm_limit"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys
=
"api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...
...
@@ -181,6 +183,7 @@ var Columns = []string{
FieldRequirePrivacySet
,
FieldDefaultMappedModel
,
FieldMessagesDispatchModelConfig
,
FieldRpmLimit
,
}
var
(
...
...
@@ -258,6 +261,8 @@ var (
DefaultMappedModelValidator
func
(
string
)
error
// DefaultMessagesDispatchModelConfig holds the default value on creation for the "messages_dispatch_model_config" field.
DefaultMessagesDispatchModelConfig
domain
.
OpenAIMessagesDispatchModelConfig
// DefaultRpmLimit holds the default value on creation for the "rpm_limit" field.
DefaultRpmLimit
int
)
// OrderOption defines the ordering options for the Group queries.
...
...
@@ -403,6 +408,11 @@ func ByDefaultMappedModel(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldDefaultMappedModel
,
opts
...
)
.
ToFunc
()
}
// ByRpmLimit orders the results by the rpm_limit field.
func
ByRpmLimit
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldRpmLimit
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group/where.go
View file @
6b0cf466
...
...
@@ -190,6 +190,11 @@ func DefaultMappedModel(v string) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldDefaultMappedModel
,
v
))
}
// RpmLimit applies equality check predicate on the "rpm_limit" field. It's identical to RpmLimitEQ.
func
RpmLimit
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldRpmLimit
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
...
@@ -1320,6 +1325,46 @@ func DefaultMappedModelContainsFold(v string) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldContainsFold
(
FieldDefaultMappedModel
,
v
))
}
// RpmLimitEQ applies the EQ predicate on the "rpm_limit" field.
func
RpmLimitEQ
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldRpmLimit
,
v
))
}
// RpmLimitNEQ applies the NEQ predicate on the "rpm_limit" field.
func
RpmLimitNEQ
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldRpmLimit
,
v
))
}
// RpmLimitIn applies the In predicate on the "rpm_limit" field.
func
RpmLimitIn
(
vs
...
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIn
(
FieldRpmLimit
,
vs
...
))
}
// RpmLimitNotIn applies the NotIn predicate on the "rpm_limit" field.
func
RpmLimitNotIn
(
vs
...
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNotIn
(
FieldRpmLimit
,
vs
...
))
}
// RpmLimitGT applies the GT predicate on the "rpm_limit" field.
func
RpmLimitGT
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGT
(
FieldRpmLimit
,
v
))
}
// RpmLimitGTE applies the GTE predicate on the "rpm_limit" field.
func
RpmLimitGTE
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGTE
(
FieldRpmLimit
,
v
))
}
// RpmLimitLT applies the LT predicate on the "rpm_limit" field.
func
RpmLimitLT
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLT
(
FieldRpmLimit
,
v
))
}
// RpmLimitLTE applies the LTE predicate on the "rpm_limit" field.
func
RpmLimitLTE
(
v
int
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLTE
(
FieldRpmLimit
,
v
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
Group
{
return
predicate
.
Group
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group_create.go
View file @
6b0cf466
...
...
@@ -425,6 +425,20 @@ func (_c *GroupCreate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe
return
_c
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_c
*
GroupCreate
)
SetRpmLimit
(
v
int
)
*
GroupCreate
{
_c
.
mutation
.
SetRpmLimit
(
v
)
return
_c
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_c
*
GroupCreate
)
SetNillableRpmLimit
(
v
*
int
)
*
GroupCreate
{
if
v
!=
nil
{
_c
.
SetRpmLimit
(
*
v
)
}
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
GroupCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -630,6 +644,10 @@ func (_c *GroupCreate) defaults() error {
v
:=
group
.
DefaultMessagesDispatchModelConfig
_c
.
mutation
.
SetMessagesDispatchModelConfig
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
RpmLimit
();
!
ok
{
v
:=
group
.
DefaultRpmLimit
_c
.
mutation
.
SetRpmLimit
(
v
)
}
return
nil
}
...
...
@@ -717,6 +735,9 @@ func (_c *GroupCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
MessagesDispatchModelConfig
();
!
ok
{
return
&
ValidationError
{
Name
:
"messages_dispatch_model_config"
,
err
:
errors
.
New
(
`ent: missing required field "Group.messages_dispatch_model_config"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
RpmLimit
();
!
ok
{
return
&
ValidationError
{
Name
:
"rpm_limit"
,
err
:
errors
.
New
(
`ent: missing required field "Group.rpm_limit"`
)}
}
return
nil
}
...
...
@@ -864,6 +885,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
group
.
FieldMessagesDispatchModelConfig
,
field
.
TypeJSON
,
value
)
_node
.
MessagesDispatchModelConfig
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
group
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
_node
.
RpmLimit
=
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1500,6 +1525,24 @@ func (u *GroupUpsert) UpdateMessagesDispatchModelConfig() *GroupUpsert {
return
u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
GroupUpsert
)
SetRpmLimit
(
v
int
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldRpmLimit
,
v
)
return
u
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateRpmLimit
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldRpmLimit
)
return
u
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
GroupUpsert
)
AddRpmLimit
(
v
int
)
*
GroupUpsert
{
u
.
Add
(
group
.
FieldRpmLimit
,
v
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
...
...
@@ -2105,6 +2148,27 @@ func (u *GroupUpsertOne) UpdateMessagesDispatchModelConfig() *GroupUpsertOne {
})
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
GroupUpsertOne
)
SetRpmLimit
(
v
int
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetRpmLimit
(
v
)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
GroupUpsertOne
)
AddRpmLimit
(
v
int
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddRpmLimit
(
v
)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateRpmLimit
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateRpmLimit
()
})
}
// Exec executes the query.
func
(
u
*
GroupUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
...
@@ -2876,6 +2940,27 @@ func (u *GroupUpsertBulk) UpdateMessagesDispatchModelConfig() *GroupUpsertBulk {
})
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
GroupUpsertBulk
)
SetRpmLimit
(
v
int
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetRpmLimit
(
v
)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
GroupUpsertBulk
)
AddRpmLimit
(
v
int
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddRpmLimit
(
v
)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateRpmLimit
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateRpmLimit
()
})
}
// Exec executes the query.
func
(
u
*
GroupUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/group_update.go
View file @
6b0cf466
...
...
@@ -567,6 +567,27 @@ func (_u *GroupUpdate) SetNillableMessagesDispatchModelConfig(v *domain.OpenAIMe
return
_u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_u
*
GroupUpdate
)
SetRpmLimit
(
v
int
)
*
GroupUpdate
{
_u
.
mutation
.
ResetRpmLimit
()
_u
.
mutation
.
SetRpmLimit
(
v
)
return
_u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_u
*
GroupUpdate
)
SetNillableRpmLimit
(
v
*
int
)
*
GroupUpdate
{
if
v
!=
nil
{
_u
.
SetRpmLimit
(
*
v
)
}
return
_u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func
(
_u
*
GroupUpdate
)
AddRpmLimit
(
v
int
)
*
GroupUpdate
{
_u
.
mutation
.
AddRpmLimit
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -1030,6 +1051,12 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
MessagesDispatchModelConfig
();
ok
{
_spec
.
SetField
(
group
.
FieldMessagesDispatchModelConfig
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
group
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedRpmLimit
();
ok
{
_spec
.
AddField
(
group
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1875,6 +1902,27 @@ func (_u *GroupUpdateOne) SetNillableMessagesDispatchModelConfig(v *domain.OpenA
return
_u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_u
*
GroupUpdateOne
)
SetRpmLimit
(
v
int
)
*
GroupUpdateOne
{
_u
.
mutation
.
ResetRpmLimit
()
_u
.
mutation
.
SetRpmLimit
(
v
)
return
_u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_u
*
GroupUpdateOne
)
SetNillableRpmLimit
(
v
*
int
)
*
GroupUpdateOne
{
if
v
!=
nil
{
_u
.
SetRpmLimit
(
*
v
)
}
return
_u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func
(
_u
*
GroupUpdateOne
)
AddRpmLimit
(
v
int
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddRpmLimit
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -2368,6 +2416,12 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if
value
,
ok
:=
_u
.
mutation
.
MessagesDispatchModelConfig
();
ok
{
_spec
.
SetField
(
group
.
FieldMessagesDispatchModelConfig
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
group
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedRpmLimit
();
ok
{
_spec
.
AddField
(
group
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
backend/ent/migrate/schema.go
View file @
6b0cf466
...
...
@@ -491,6 +491,7 @@ var (
{
Name
:
"require_privacy_set"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"default_mapped_model"
,
Type
:
field
.
TypeString
,
Size
:
100
,
Default
:
""
},
{
Name
:
"messages_dispatch_model_config"
,
Type
:
field
.
TypeJSON
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"rpm_limit"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable
=
&
schema
.
Table
{
...
...
@@ -1276,7 +1277,7 @@ var (
{
Name
:
"totp_secret_encrypted"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"totp_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"totp_enabled_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"signup_source"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"email"
},
{
Name
:
"signup_source"
,
Type
:
field
.
TypeString
,
Default
:
"email"
},
{
Name
:
"last_login_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"last_active_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"balance_notify_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
true
},
...
...
@@ -1284,6 +1285,7 @@ var (
{
Name
:
"balance_notify_threshold"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"balance_notify_extra_emails"
,
Type
:
field
.
TypeString
,
Default
:
"[]"
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"total_recharged"
,
Type
:
field
.
TypeFloat64
,
Default
:
0
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"rpm_limit"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
}
// UsersTable holds the schema information for the "users" table.
UsersTable
=
&
schema
.
Table
{
...
...
backend/ent/mutation.go
View file @
6b0cf466
...
...
@@ -10102,6 +10102,8 @@ type GroupMutation struct {
require_privacy_set *bool
default_mapped_model *string
messages_dispatch_model_config *domain.OpenAIMessagesDispatchModelConfig
rpm_limit *int
addrpm_limit *int
clearedFields map[string]struct{}
api_keys map[int64]struct{}
removedapi_keys map[int64]struct{}
...
...
@@ -11690,6 +11692,62 @@ func (m *GroupMutation) ResetMessagesDispatchModelConfig() {
m.messages_dispatch_model_config = nil
}
// SetRpmLimit sets the "rpm_limit" field.
func (m *GroupMutation) SetRpmLimit(i int) {
m.rpm_limit = &i
m.addrpm_limit = nil
}
// RpmLimit returns the value of the "rpm_limit" field in the mutation.
func (m *GroupMutation) RpmLimit() (r int, exists bool) {
v := m.rpm_limit
if v == nil {
return
}
return *v, true
}
// OldRpmLimit returns the old "rpm_limit" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldRpmLimit(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRpmLimit is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRpmLimit requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRpmLimit: %w", err)
}
return oldValue.RpmLimit, nil
}
// AddRpmLimit adds i to the "rpm_limit" field.
func (m *GroupMutation) AddRpmLimit(i int) {
if m.addrpm_limit != nil {
*m.addrpm_limit += i
} else {
m.addrpm_limit = &i
}
}
// AddedRpmLimit returns the value that was added to the "rpm_limit" field in this mutation.
func (m *GroupMutation) AddedRpmLimit() (r int, exists bool) {
v := m.addrpm_limit
if v == nil {
return
}
return *v, true
}
// ResetRpmLimit resets all changes to the "rpm_limit" field.
func (m *GroupMutation) ResetRpmLimit() {
m.rpm_limit = nil
m.addrpm_limit = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil {
...
...
@@ -12048,7 +12106,7 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 3
0
)
fields := make([]string, 0, 3
1
)
if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt)
}
...
...
@@ -12139,6 +12197,9 @@ func (m *GroupMutation) Fields() []string {
if m.messages_dispatch_model_config != nil {
fields = append(fields, group.FieldMessagesDispatchModelConfig)
}
if m.rpm_limit != nil {
fields = append(fields, group.FieldRpmLimit)
}
return fields
}
...
...
@@ -12207,6 +12268,8 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
return m.DefaultMappedModel()
case group.FieldMessagesDispatchModelConfig:
return m.MessagesDispatchModelConfig()
case group.FieldRpmLimit:
return m.RpmLimit()
}
return nil, false
}
...
...
@@ -12276,6 +12339,8 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
return m.OldDefaultMappedModel(ctx)
case group.FieldMessagesDispatchModelConfig:
return m.OldMessagesDispatchModelConfig(ctx)
case group.FieldRpmLimit:
return m.OldRpmLimit(ctx)
}
return nil, fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -12495,6 +12560,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
}
m.SetMessagesDispatchModelConfig(v)
return nil
case group.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRpmLimit(v)
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -12536,6 +12608,9 @@ func (m *GroupMutation) AddedFields() []string {
if m.addsort_order != nil {
fields = append(fields, group.FieldSortOrder)
}
if m.addrpm_limit != nil {
fields = append(fields, group.FieldRpmLimit)
}
return fields
}
...
...
@@ -12566,6 +12641,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedFallbackGroupIDOnInvalidRequest()
case group.FieldSortOrder:
return m.AddedSortOrder()
case group.FieldRpmLimit:
return m.AddedRpmLimit()
}
return nil, false
}
...
...
@@ -12652,6 +12729,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error {
}
m.AddSortOrder(v)
return nil
case group.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRpmLimit(v)
return nil
}
return fmt.Errorf("unknown Group numeric field %s", name)
}
...
...
@@ -12838,6 +12922,9 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldMessagesDispatchModelConfig:
m.ResetMessagesDispatchModelConfig()
return nil
case group.FieldRpmLimit:
m.ResetRpmLimit()
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -32681,6 +32768,8 @@ type UserMutation struct {
balance_notify_extra_emails *string
total_recharged *float64
addtotal_recharged *float64
rpm_limit *int
addrpm_limit *int
clearedFields map[string]struct{}
api_keys map[int64]struct{}
removedapi_keys map[int64]struct{}
...
...
@@ -33772,6 +33861,62 @@ func (m *UserMutation) ResetTotalRecharged() {
m.addtotal_recharged = nil
}
// SetRpmLimit sets the "rpm_limit" field.
func (m *UserMutation) SetRpmLimit(i int) {
m.rpm_limit = &i
m.addrpm_limit = nil
}
// RpmLimit returns the value of the "rpm_limit" field in the mutation.
func (m *UserMutation) RpmLimit() (r int, exists bool) {
v := m.rpm_limit
if v == nil {
return
}
return *v, true
}
// OldRpmLimit returns the old "rpm_limit" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldRpmLimit(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRpmLimit is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRpmLimit requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRpmLimit: %w", err)
}
return oldValue.RpmLimit, nil
}
// AddRpmLimit adds i to the "rpm_limit" field.
func (m *UserMutation) AddRpmLimit(i int) {
if m.addrpm_limit != nil {
*m.addrpm_limit += i
} else {
m.addrpm_limit = &i
}
}
// AddedRpmLimit returns the value that was added to the "rpm_limit" field in this mutation.
func (m *UserMutation) AddedRpmLimit() (r int, exists bool) {
v := m.addrpm_limit
if v == nil {
return
}
return *v, true
}
// ResetRpmLimit resets all changes to the "rpm_limit" field.
func (m *UserMutation) ResetRpmLimit() {
m.rpm_limit = nil
m.addrpm_limit = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *UserMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil {
...
...
@@ -34454,7 +34599,7 @@ func (m *UserMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 2
2
)
fields := make([]string, 0, 2
3
)
if m.created_at != nil {
fields = append(fields, user.FieldCreatedAt)
}
...
...
@@ -34521,6 +34666,9 @@ func (m *UserMutation) Fields() []string {
if m.total_recharged != nil {
fields = append(fields, user.FieldTotalRecharged)
}
if m.rpm_limit != nil {
fields = append(fields, user.FieldRpmLimit)
}
return fields
}
...
...
@@ -34573,6 +34721,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
return m.BalanceNotifyExtraEmails()
case user.FieldTotalRecharged:
return m.TotalRecharged()
case user.FieldRpmLimit:
return m.RpmLimit()
}
return nil, false
}
...
...
@@ -34626,6 +34776,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldBalanceNotifyExtraEmails(ctx)
case user.FieldTotalRecharged:
return m.OldTotalRecharged(ctx)
case user.FieldRpmLimit:
return m.OldRpmLimit(ctx)
}
return nil, fmt.Errorf("unknown User field %s", name)
}
...
...
@@ -34789,6 +34941,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
}
m.SetTotalRecharged(v)
return nil
case user.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRpmLimit(v)
return nil
}
return fmt.Errorf("unknown User field %s", name)
}
...
...
@@ -34809,6 +34968,9 @@ func (m *UserMutation) AddedFields() []string {
if m.addtotal_recharged != nil {
fields = append(fields, user.FieldTotalRecharged)
}
if m.addrpm_limit != nil {
fields = append(fields, user.FieldRpmLimit)
}
return fields
}
...
...
@@ -34825,6 +34987,8 @@ func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedBalanceNotifyThreshold()
case user.FieldTotalRecharged:
return m.AddedTotalRecharged()
case user.FieldRpmLimit:
return m.AddedRpmLimit()
}
return nil, false
}
...
...
@@ -34862,6 +35026,13 @@ func (m *UserMutation) AddField(name string, value ent.Value) error {
}
m.AddTotalRecharged(v)
return nil
case user.FieldRpmLimit:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRpmLimit(v)
return nil
}
return fmt.Errorf("unknown User numeric field %s", name)
}
...
...
@@ -34994,6 +35165,9 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldTotalRecharged:
m.ResetTotalRecharged()
return nil
case user.FieldRpmLimit:
m.ResetRpmLimit()
return nil
}
return fmt.Errorf("unknown User field %s", name)
}
backend/ent/runtime/runtime.go
View file @
6b0cf466
...
...
@@ -595,6 +595,10 @@ func init() {
groupDescMessagesDispatchModelConfig
:=
groupFields
[
26
]
.
Descriptor
()
// group.DefaultMessagesDispatchModelConfig holds the default value on creation for the messages_dispatch_model_config field.
group
.
DefaultMessagesDispatchModelConfig
=
groupDescMessagesDispatchModelConfig
.
Default
.
(
domain
.
OpenAIMessagesDispatchModelConfig
)
// groupDescRpmLimit is the schema descriptor for rpm_limit field.
groupDescRpmLimit
:=
groupFields
[
27
]
.
Descriptor
()
// group.DefaultRpmLimit holds the default value on creation for the rpm_limit field.
group
.
DefaultRpmLimit
=
groupDescRpmLimit
.
Default
.
(
int
)
idempotencyrecordMixin
:=
schema
.
IdempotencyRecord
{}
.
Mixin
()
idempotencyrecordMixinFields0
:=
idempotencyrecordMixin
[
0
]
.
Fields
()
_
=
idempotencyrecordMixinFields0
...
...
@@ -1575,6 +1579,10 @@ func init() {
userDescTotalRecharged
:=
userFields
[
18
]
.
Descriptor
()
// user.DefaultTotalRecharged holds the default value on creation for the total_recharged field.
user
.
DefaultTotalRecharged
=
userDescTotalRecharged
.
Default
.
(
float64
)
// userDescRpmLimit is the schema descriptor for rpm_limit field.
userDescRpmLimit
:=
userFields
[
19
]
.
Descriptor
()
// user.DefaultRpmLimit holds the default value on creation for the rpm_limit field.
user
.
DefaultRpmLimit
=
userDescRpmLimit
.
Default
.
(
int
)
userallowedgroupFields
:=
schema
.
UserAllowedGroup
{}
.
Fields
()
_
=
userallowedgroupFields
// userallowedgroupDescCreatedAt is the schema descriptor for created_at field.
...
...
backend/ent/schema/group.go
View file @
6b0cf466
...
...
@@ -145,6 +145,11 @@ func (Group) Fields() []ent.Field {
Default
(
domain
.
OpenAIMessagesDispatchModelConfig
{})
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"jsonb"
})
.
Comment
(
"OpenAI Messages 调度模型配置:按 Claude 系列/精确模型映射到目标 GPT 模型"
),
// 分组级每分钟请求数上限(0 = 不限制)。设置后优先于用户级兜底生效。
field
.
Int
(
"rpm_limit"
)
.
Default
(
0
)
.
Comment
(
"分组 RPM 上限,0 表示不限制;设置后接管该分组用户的限流"
),
}
}
...
...
backend/ent/schema/user.go
View file @
6b0cf466
...
...
@@ -108,6 +108,10 @@ func (User) Fields() []ent.Field {
field
.
Float
(
"total_recharged"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"decimal(20,8)"
})
.
Default
(
0
),
// 用户级每分钟请求数上限(0 = 不限制)。仅当所在分组未设置 rpm_limit 时作为兜底生效。
field
.
Int
(
"rpm_limit"
)
.
Default
(
0
),
}
}
...
...
backend/ent/user.go
View file @
6b0cf466
...
...
@@ -61,6 +61,8 @@ type User struct {
BalanceNotifyExtraEmails
string
`json:"balance_notify_extra_emails,omitempty"`
// TotalRecharged holds the value of the "total_recharged" field.
TotalRecharged
float64
`json:"total_recharged,omitempty"`
// RpmLimit holds the value of the "rpm_limit" field.
RpmLimit
int
`json:"rpm_limit,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set.
Edges
UserEdges
`json:"edges"`
...
...
@@ -226,7 +228,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
values
[
i
]
=
new
(
sql
.
NullBool
)
case
user
.
FieldBalance
,
user
.
FieldBalanceNotifyThreshold
,
user
.
FieldTotalRecharged
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
user
.
FieldID
,
user
.
FieldConcurrency
:
case
user
.
FieldID
,
user
.
FieldConcurrency
,
user
.
FieldRpmLimit
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
,
user
.
FieldTotpSecretEncrypted
,
user
.
FieldSignupSource
,
user
.
FieldBalanceNotifyThresholdType
,
user
.
FieldBalanceNotifyExtraEmails
:
values
[
i
]
=
new
(
sql
.
NullString
)
...
...
@@ -391,6 +393,12 @@ func (_m *User) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
_m
.
TotalRecharged
=
value
.
Float64
}
case
user
.
FieldRpmLimit
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field rpm_limit"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
RpmLimit
=
int
(
value
.
Int64
)
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
...
...
@@ -569,6 +577,9 @@ func (_m *User) String() string {
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"total_recharged="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
TotalRecharged
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"rpm_limit="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
RpmLimit
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
...
...
backend/ent/user/user.go
View file @
6b0cf466
...
...
@@ -59,6 +59,8 @@ const (
FieldBalanceNotifyExtraEmails
=
"balance_notify_extra_emails"
// FieldTotalRecharged holds the string denoting the total_recharged field in the database.
FieldTotalRecharged
=
"total_recharged"
// FieldRpmLimit holds the string denoting the rpm_limit field in the database.
FieldRpmLimit
=
"rpm_limit"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys
=
"api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...
...
@@ -203,6 +205,7 @@ var Columns = []string{
FieldBalanceNotifyThreshold
,
FieldBalanceNotifyExtraEmails
,
FieldTotalRecharged
,
FieldRpmLimit
,
}
var
(
...
...
@@ -271,6 +274,8 @@ var (
DefaultBalanceNotifyExtraEmails
string
// DefaultTotalRecharged holds the default value on creation for the "total_recharged" field.
DefaultTotalRecharged
float64
// DefaultRpmLimit holds the default value on creation for the "rpm_limit" field.
DefaultRpmLimit
int
)
// OrderOption defines the ordering options for the User queries.
...
...
@@ -391,6 +396,11 @@ func ByTotalRecharged(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldTotalRecharged
,
opts
...
)
.
ToFunc
()
}
// ByRpmLimit orders the results by the rpm_limit field.
func
ByRpmLimit
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldRpmLimit
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user/where.go
View file @
6b0cf466
...
...
@@ -165,6 +165,11 @@ func TotalRecharged(v float64) predicate.User {
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotalRecharged
,
v
))
}
// RpmLimit applies equality check predicate on the "rpm_limit" field. It's identical to RpmLimitEQ.
func
RpmLimit
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldRpmLimit
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
...
@@ -1295,6 +1300,46 @@ func TotalRechargedLTE(v float64) predicate.User {
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldTotalRecharged
,
v
))
}
// RpmLimitEQ applies the EQ predicate on the "rpm_limit" field.
func
RpmLimitEQ
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldRpmLimit
,
v
))
}
// RpmLimitNEQ applies the NEQ predicate on the "rpm_limit" field.
func
RpmLimitNEQ
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldRpmLimit
,
v
))
}
// RpmLimitIn applies the In predicate on the "rpm_limit" field.
func
RpmLimitIn
(
vs
...
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldRpmLimit
,
vs
...
))
}
// RpmLimitNotIn applies the NotIn predicate on the "rpm_limit" field.
func
RpmLimitNotIn
(
vs
...
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldRpmLimit
,
vs
...
))
}
// RpmLimitGT applies the GT predicate on the "rpm_limit" field.
func
RpmLimitGT
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldRpmLimit
,
v
))
}
// RpmLimitGTE applies the GTE predicate on the "rpm_limit" field.
func
RpmLimitGTE
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldRpmLimit
,
v
))
}
// RpmLimitLT applies the LT predicate on the "rpm_limit" field.
func
RpmLimitLT
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldRpmLimit
,
v
))
}
// RpmLimitLTE applies the LTE predicate on the "rpm_limit" field.
func
RpmLimitLTE
(
v
int
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldRpmLimit
,
v
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user_create.go
View file @
6b0cf466
...
...
@@ -325,6 +325,20 @@ func (_c *UserCreate) SetNillableTotalRecharged(v *float64) *UserCreate {
return
_c
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_c
*
UserCreate
)
SetRpmLimit
(
v
int
)
*
UserCreate
{
_c
.
mutation
.
SetRpmLimit
(
v
)
return
_c
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableRpmLimit
(
v
*
int
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetRpmLimit
(
*
v
)
}
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
UserCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -604,6 +618,10 @@ func (_c *UserCreate) defaults() error {
v
:=
user
.
DefaultTotalRecharged
_c
.
mutation
.
SetTotalRecharged
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
RpmLimit
();
!
ok
{
v
:=
user
.
DefaultRpmLimit
_c
.
mutation
.
SetRpmLimit
(
v
)
}
return
nil
}
...
...
@@ -687,6 +705,9 @@ func (_c *UserCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
TotalRecharged
();
!
ok
{
return
&
ValidationError
{
Name
:
"total_recharged"
,
err
:
errors
.
New
(
`ent: missing required field "User.total_recharged"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
RpmLimit
();
!
ok
{
return
&
ValidationError
{
Name
:
"rpm_limit"
,
err
:
errors
.
New
(
`ent: missing required field "User.rpm_limit"`
)}
}
return
nil
}
...
...
@@ -802,6 +823,10 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
user
.
FieldTotalRecharged
,
field
.
TypeFloat64
,
value
)
_node
.
TotalRecharged
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
user
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
_node
.
RpmLimit
=
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1362,6 +1387,24 @@ func (u *UserUpsert) AddTotalRecharged(v float64) *UserUpsert {
return
u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
UserUpsert
)
SetRpmLimit
(
v
int
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldRpmLimit
,
v
)
return
u
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateRpmLimit
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldRpmLimit
)
return
u
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
UserUpsert
)
AddRpmLimit
(
v
int
)
*
UserUpsert
{
u
.
Add
(
user
.
FieldRpmLimit
,
v
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
...
...
@@ -1771,6 +1814,27 @@ func (u *UserUpsertOne) UpdateTotalRecharged() *UserUpsertOne {
})
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
UserUpsertOne
)
SetRpmLimit
(
v
int
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetRpmLimit
(
v
)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
UserUpsertOne
)
AddRpmLimit
(
v
int
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
AddRpmLimit
(
v
)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateRpmLimit
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateRpmLimit
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
...
@@ -2346,6 +2410,27 @@ func (u *UserUpsertBulk) UpdateTotalRecharged() *UserUpsertBulk {
})
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
u
*
UserUpsertBulk
)
SetRpmLimit
(
v
int
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetRpmLimit
(
v
)
})
}
// AddRpmLimit adds v to the "rpm_limit" field.
func
(
u
*
UserUpsertBulk
)
AddRpmLimit
(
v
int
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
AddRpmLimit
(
v
)
})
}
// UpdateRpmLimit sets the "rpm_limit" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateRpmLimit
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateRpmLimit
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/user_update.go
View file @
6b0cf466
...
...
@@ -389,6 +389,27 @@ func (_u *UserUpdate) AddTotalRecharged(v float64) *UserUpdate {
return
_u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_u
*
UserUpdate
)
SetRpmLimit
(
v
int
)
*
UserUpdate
{
_u
.
mutation
.
ResetRpmLimit
()
_u
.
mutation
.
SetRpmLimit
(
v
)
return
_u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableRpmLimit
(
v
*
int
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetRpmLimit
(
*
v
)
}
return
_u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func
(
_u
*
UserUpdate
)
AddRpmLimit
(
v
int
)
*
UserUpdate
{
_u
.
mutation
.
AddRpmLimit
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -1008,6 +1029,12 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
AddedTotalRecharged
();
ok
{
_spec
.
AddField
(
user
.
FieldTotalRecharged
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
user
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedRpmLimit
();
ok
{
_spec
.
AddField
(
user
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1930,6 +1957,27 @@ func (_u *UserUpdateOne) AddTotalRecharged(v float64) *UserUpdateOne {
return
_u
}
// SetRpmLimit sets the "rpm_limit" field.
func
(
_u
*
UserUpdateOne
)
SetRpmLimit
(
v
int
)
*
UserUpdateOne
{
_u
.
mutation
.
ResetRpmLimit
()
_u
.
mutation
.
SetRpmLimit
(
v
)
return
_u
}
// SetNillableRpmLimit sets the "rpm_limit" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableRpmLimit
(
v
*
int
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetRpmLimit
(
*
v
)
}
return
_u
}
// AddRpmLimit adds value to the "rpm_limit" field.
func
(
_u
*
UserUpdateOne
)
AddRpmLimit
(
v
int
)
*
UserUpdateOne
{
_u
.
mutation
.
AddRpmLimit
(
v
)
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -2579,6 +2627,12 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if
value
,
ok
:=
_u
.
mutation
.
AddedTotalRecharged
();
ok
{
_spec
.
AddField
(
user
.
FieldTotalRecharged
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
RpmLimit
();
ok
{
_spec
.
SetField
(
user
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedRpmLimit
();
ok
{
_spec
.
AddField
(
user
.
FieldRpmLimit
,
field
.
TypeInt
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
backend/go.mod
View file @
6b0cf466
...
...
@@ -104,6 +104,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
...
...
backend/go.sum
View file @
6b0cf466
...
...
@@ -162,6 +162,8 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
...
...
@@ -216,6 +218,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
...
...
@@ -249,6 +253,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
...
...
@@ -278,6 +284,8 @@ github.com/refraction-networking/utls v1.8.2 h1:j4Q1gJj0xngdeH+Ox/qND11aEfhpgoEv
github.com/refraction-networking/utls v1.8.2/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
...
...
@@ -310,6 +318,8 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
...
...
backend/internal/handler/admin/admin_service_stub_test.go
View file @
6b0cf466
...
...
@@ -183,6 +183,17 @@ func (s *stubAdminService) GetUserUsageStats(ctx context.Context, userID int64,
return
map
[
string
]
any
{
"user_id"
:
userID
},
nil
}
func
(
s
*
stubAdminService
)
GetUserRPMStatus
(
ctx
context
.
Context
,
userID
int64
)
(
*
service
.
UserRPMStatus
,
error
)
{
user
,
err
:=
s
.
GetUser
(
ctx
,
userID
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
service
.
UserRPMStatus
{
UserRPMUsed
:
0
,
UserRPMLimit
:
user
.
RPMLimit
,
},
nil
}
func
(
s
*
stubAdminService
)
BindUserAuthIdentity
(
ctx
context
.
Context
,
userID
int64
,
input
service
.
AdminBindAuthIdentityInput
)
(
*
service
.
AdminBoundAuthIdentity
,
error
)
{
s
.
boundAuthIdentityFor
=
userID
copied
:=
input
...
...
@@ -276,6 +287,14 @@ func (s *stubAdminService) BatchSetGroupRateMultipliers(_ context.Context, _ int
return
nil
}
func
(
s
*
stubAdminService
)
ClearGroupRPMOverrides
(
_
context
.
Context
,
_
int64
)
error
{
return
nil
}
func
(
s
*
stubAdminService
)
BatchSetGroupRPMOverrides
(
_
context
.
Context
,
_
int64
,
_
[]
service
.
GroupRPMOverrideInput
)
error
{
return
nil
}
func
(
s
*
stubAdminService
)
ListAccounts
(
ctx
context
.
Context
,
page
,
pageSize
int
,
platform
,
accountType
,
status
,
search
string
,
groupID
int64
,
privacyMode
string
,
sortBy
,
sortOrder
string
)
([]
service
.
Account
,
int64
,
error
)
{
s
.
lastListAccounts
.
platform
=
platform
s
.
lastListAccounts
.
accountType
=
accountType
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment