🐛 Fix api key missing account id

This commit is contained in:
LittleSheep 2024-08-25 23:15:29 +08:00
parent b097dab9e1
commit 46c7b6dff1
3 changed files with 10 additions and 4 deletions

9
.idea/workspace.xml generated
View File

@ -4,9 +4,10 @@
<option name="autoReloadType" value="ALL" />
</component>
<component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix path parameters misplaced">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix api key wasn't in auto maintain range">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/database/migrator.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/database/migrator.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/models/bot.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/models/bot.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/bot_token.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/bot_token.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -153,7 +154,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value=":recycle: Refactored relation system&#10;:arrow_up: Support new realm &amp; relation api" />
<MESSAGE value=":bug: Fix model relation issue" />
<MESSAGE value=":arrow_up: Upgrade dealer" />
<MESSAGE value=":sparkles: Support stream controller event emit" />
@ -178,7 +178,8 @@
<MESSAGE value=":sparkles: Bot related bot key apis" />
<MESSAGE value=":bug: Fix bot related bot key apis path error" />
<MESSAGE value=":bug: Fix path parameters misplaced" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix path parameters misplaced" />
<MESSAGE value=":bug: Fix api key wasn't in auto maintain range" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix api key wasn't in auto maintain range" />
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>

View File

@ -8,4 +8,6 @@ type ApiKey struct {
Lifecycle *int64 `json:"lifecycle"`
Ticket AuthTicket `json:"ticket" gorm:"TicketID"`
TicketID uint `json:"ticket_id"`
Account Account `json:"account"`
AccountID uint `json:"account_id"`
}

View File

@ -9,6 +9,9 @@ import (
)
func NewApiKey(user models.Account, key models.ApiKey, ip, ua string, claims []string) (models.ApiKey, error) {
key.Account = user
key.AccountID = user.ID
var expiredAt *time.Time
if key.Lifecycle != nil {
expiredAt = lo.ToPtr(time.Now().Add(time.Duration(*key.Lifecycle) * time.Second))