密钥: 删除改为硬删(立即失效不可恢复)

- DELETE /api/v1/keys/:id 由软吊销(置 revoked)改为物理删除

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-08-16 09:04:18 +08:00
co-authored by Claude
parent 0ee92d78e7
commit fb7db00817
+3 -5
View File
@@ -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 {