密钥: 删除改为硬删(立即失效不可恢复)
- 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})
|
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) {
|
func (h *Handler) DeleteKey(c *gin.Context) {
|
||||||
u, ok := userFromContext(c)
|
u, ok := userFromContext(c)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -172,11 +172,9 @@ func (h *Handler) DeleteKey(c *gin.Context) {
|
|||||||
resp.Fail(c, http.StatusBadRequest, "invalid key id")
|
resp.Fail(c, http.StatusBadRequest, "invalid key id")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res := h.a.DB.Model(&store.APIKey{}).
|
res := h.a.DB.Where("id = ? AND user_id = ?", id, u.ID).Delete(&store.APIKey{})
|
||||||
Where("id = ? AND user_id = ?", id, u.ID).
|
|
||||||
Update("status", store.KeyStatusRevoked)
|
|
||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
resp.Fail(c, http.StatusInternalServerError, "failed to revoke key")
|
resp.Fail(c, http.StatusInternalServerError, "failed to delete key")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if res.RowsAffected == 0 {
|
if res.RowsAffected == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user