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
18ba8d91
Commit
18ba8d91
authored
Mar 12, 2026
by
ius
Browse files
fix: stabilize repository integration paths
parent
e97fd7e8
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/repository/fixtures_integration_test.go
View file @
18ba8d91
...
@@ -262,6 +262,42 @@ func mustCreateApiKey(t *testing.T, client *dbent.Client, k *service.APIKey) *se
...
@@ -262,6 +262,42 @@ func mustCreateApiKey(t *testing.T, client *dbent.Client, k *service.APIKey) *se
SetKey
(
k
.
Key
)
.
SetKey
(
k
.
Key
)
.
SetName
(
k
.
Name
)
.
SetName
(
k
.
Name
)
.
SetStatus
(
k
.
Status
)
SetStatus
(
k
.
Status
)
if
k
.
Quota
!=
0
{
create
.
SetQuota
(
k
.
Quota
)
}
if
k
.
QuotaUsed
!=
0
{
create
.
SetQuotaUsed
(
k
.
QuotaUsed
)
}
if
k
.
RateLimit5h
!=
0
{
create
.
SetRateLimit5h
(
k
.
RateLimit5h
)
}
if
k
.
RateLimit1d
!=
0
{
create
.
SetRateLimit1d
(
k
.
RateLimit1d
)
}
if
k
.
RateLimit7d
!=
0
{
create
.
SetRateLimit7d
(
k
.
RateLimit7d
)
}
if
k
.
Usage5h
!=
0
{
create
.
SetUsage5h
(
k
.
Usage5h
)
}
if
k
.
Usage1d
!=
0
{
create
.
SetUsage1d
(
k
.
Usage1d
)
}
if
k
.
Usage7d
!=
0
{
create
.
SetUsage7d
(
k
.
Usage7d
)
}
if
k
.
Window5hStart
!=
nil
{
create
.
SetWindow5hStart
(
*
k
.
Window5hStart
)
}
if
k
.
Window1dStart
!=
nil
{
create
.
SetWindow1dStart
(
*
k
.
Window1dStart
)
}
if
k
.
Window7dStart
!=
nil
{
create
.
SetWindow7dStart
(
*
k
.
Window7dStart
)
}
if
k
.
ExpiresAt
!=
nil
{
create
.
SetExpiresAt
(
*
k
.
ExpiresAt
)
}
if
k
.
GroupID
!=
nil
{
if
k
.
GroupID
!=
nil
{
create
.
SetGroupID
(
*
k
.
GroupID
)
create
.
SetGroupID
(
*
k
.
GroupID
)
}
}
...
...
backend/internal/repository/usage_log_repo.go
View file @
18ba8d91
...
@@ -30,6 +30,45 @@ import (
...
@@ -30,6 +30,45 @@ import (
const
usageLogSelectColumns
=
"id, user_id, api_key_id, account_id, request_id, model, group_id, subscription_id, input_tokens, output_tokens, cache_creation_tokens, cache_read_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens, input_cost, output_cost, cache_creation_cost, cache_read_cost, total_cost, actual_cost, rate_multiplier, account_rate_multiplier, billing_type, request_type, stream, openai_ws_mode, duration_ms, first_token_ms, user_agent, ip_address, image_count, image_size, media_type, service_tier, reasoning_effort, cache_ttl_overridden, created_at"
const
usageLogSelectColumns
=
"id, user_id, api_key_id, account_id, request_id, model, group_id, subscription_id, input_tokens, output_tokens, cache_creation_tokens, cache_read_tokens, cache_creation_5m_tokens, cache_creation_1h_tokens, input_cost, output_cost, cache_creation_cost, cache_read_cost, total_cost, actual_cost, rate_multiplier, account_rate_multiplier, billing_type, request_type, stream, openai_ws_mode, duration_ms, first_token_ms, user_agent, ip_address, image_count, image_size, media_type, service_tier, reasoning_effort, cache_ttl_overridden, created_at"
var
usageLogInsertArgTypes
=
[
...
]
string
{
"bigint"
,
"bigint"
,
"bigint"
,
"text"
,
"text"
,
"bigint"
,
"bigint"
,
"integer"
,
"integer"
,
"integer"
,
"integer"
,
"integer"
,
"integer"
,
"numeric"
,
"numeric"
,
"numeric"
,
"numeric"
,
"numeric"
,
"numeric"
,
"numeric"
,
"numeric"
,
"smallint"
,
"smallint"
,
"boolean"
,
"boolean"
,
"integer"
,
"integer"
,
"text"
,
"text"
,
"integer"
,
"text"
,
"text"
,
"text"
,
"text"
,
"boolean"
,
"timestamptz"
,
}
// dateFormatWhitelist 将 granularity 参数映射为 PostgreSQL TO_CHAR 格式字符串,防止外部输入直接拼入 SQL
// dateFormatWhitelist 将 granularity 参数映射为 PostgreSQL TO_CHAR 格式字符串,防止外部输入直接拼入 SQL
var
dateFormatWhitelist
=
map
[
string
]
string
{
var
dateFormatWhitelist
=
map
[
string
]
string
{
"hour"
:
"YYYY-MM-DD HH24:00"
,
"hour"
:
"YYYY-MM-DD HH24:00"
,
...
@@ -713,6 +752,10 @@ func buildUsageLogBatchInsertQuery(keys []string, preparedByKey map[string]usage
...
@@ -713,6 +752,10 @@ func buildUsageLogBatchInsertQuery(keys []string, preparedByKey map[string]usage
_
,
_
=
query
.
WriteString
(
","
)
_
,
_
=
query
.
WriteString
(
","
)
_
,
_
=
query
.
WriteString
(
"$"
)
_
,
_
=
query
.
WriteString
(
"$"
)
_
,
_
=
query
.
WriteString
(
strconv
.
Itoa
(
argPos
))
_
,
_
=
query
.
WriteString
(
strconv
.
Itoa
(
argPos
))
if
i
<
len
(
usageLogInsertArgTypes
)
{
_
,
_
=
query
.
WriteString
(
"::"
)
_
,
_
=
query
.
WriteString
(
usageLogInsertArgTypes
[
i
])
}
argPos
++
argPos
++
}
}
_
,
_
=
query
.
WriteString
(
")"
)
_
,
_
=
query
.
WriteString
(
")"
)
...
@@ -877,6 +920,10 @@ func buildUsageLogBestEffortInsertQuery(preparedList []usageLogInsertPrepared) (
...
@@ -877,6 +920,10 @@ func buildUsageLogBestEffortInsertQuery(preparedList []usageLogInsertPrepared) (
}
}
_
,
_
=
query
.
WriteString
(
"$"
)
_
,
_
=
query
.
WriteString
(
"$"
)
_
,
_
=
query
.
WriteString
(
strconv
.
Itoa
(
argPos
))
_
,
_
=
query
.
WriteString
(
strconv
.
Itoa
(
argPos
))
if
i
<
len
(
usageLogInsertArgTypes
)
{
_
,
_
=
query
.
WriteString
(
"::"
)
_
,
_
=
query
.
WriteString
(
usageLogInsertArgTypes
[
i
])
}
argPos
++
argPos
++
}
}
_
,
_
=
query
.
WriteString
(
")"
)
_
,
_
=
query
.
WriteString
(
")"
)
...
...
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