mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-03-30 00:48:53 +00:00
fix: stabilize repository integration paths
This commit is contained in:
@@ -262,6 +262,42 @@ func mustCreateApiKey(t *testing.T, client *dbent.Client, k *service.APIKey) *se
|
||||
SetKey(k.Key).
|
||||
SetName(k.Name).
|
||||
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 {
|
||||
create.SetGroupID(*k.GroupID)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
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
|
||||
var dateFormatWhitelist = map[string]string{
|
||||
"hour": "YYYY-MM-DD HH24:00",
|
||||
@@ -713,6 +752,10 @@ func buildUsageLogBatchInsertQuery(keys []string, preparedByKey map[string]usage
|
||||
_, _ = query.WriteString(",")
|
||||
_, _ = query.WriteString("$")
|
||||
_, _ = query.WriteString(strconv.Itoa(argPos))
|
||||
if i < len(usageLogInsertArgTypes) {
|
||||
_, _ = query.WriteString("::")
|
||||
_, _ = query.WriteString(usageLogInsertArgTypes[i])
|
||||
}
|
||||
argPos++
|
||||
}
|
||||
_, _ = query.WriteString(")")
|
||||
@@ -877,6 +920,10 @@ func buildUsageLogBestEffortInsertQuery(preparedList []usageLogInsertPrepared) (
|
||||
}
|
||||
_, _ = query.WriteString("$")
|
||||
_, _ = query.WriteString(strconv.Itoa(argPos))
|
||||
if i < len(usageLogInsertArgTypes) {
|
||||
_, _ = query.WriteString("::")
|
||||
_, _ = query.WriteString(usageLogInsertArgTypes[i])
|
||||
}
|
||||
argPos++
|
||||
}
|
||||
_, _ = query.WriteString(")")
|
||||
|
||||
Reference in New Issue
Block a user