密钥: 删除改为硬删(立即失效不可恢复)
- DELETE /api/v1/keys/:id 由软吊销(置 revoked)改为物理删除 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -160,7 +160,7 @@ func (h *Handler) PatchKey(c *gin.Context) {
|
||||
resp.OK(c, gin.H{"ok": true})
|
||||
}
|
||||
|
||||
// DeleteKey DELETE /api/v1/keys/:id — 吊销。
|
||||
// DeleteKey DELETE /api/v1/keys/:id — 删除(硬删,立即失效不可恢复)。
|
||||
func (h *Handler) DeleteKey(c *gin.Context) {
|
||||
u, ok := userFromContext(c)
|
||||
if !ok {
|
||||
@@ -172,11 +172,9 @@ func (h *Handler) DeleteKey(c *gin.Context) {
|
||||
resp.Fail(c, http.StatusBadRequest, "invalid key id")
|
||||
return
|
||||
}
|
||||
res := h.a.DB.Model(&store.APIKey{}).
|
||||
Where("id = ? AND user_id = ?", id, u.ID).
|
||||
Update("status", store.KeyStatusRevoked)
|
||||
res := h.a.DB.Where("id = ? AND user_id = ?", id, u.ID).Delete(&store.APIKey{})
|
||||
if res.Error != nil {
|
||||
resp.Fail(c, http.StatusInternalServerError, "failed to revoke key")
|
||||
resp.Fail(c, http.StatusInternalServerError, "failed to delete key")
|
||||
return
|
||||
}
|
||||
if res.RowsAffected == 0 {
|
||||
|
||||
Reference in New Issue
Block a user