fix(api): 限制回流频率并隐藏后台错误详情 (#43)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,7 @@ type apiKeyView struct {
|
||||
// ListAPIKeys returns all issued keys with usage stats merged in.
|
||||
func (h *Handler) ListAPIKeys(w http.ResponseWriter, r *http.Request) {
|
||||
keys, err := h.store.ListAPIKeys(r.Context())
|
||||
if h.handleErr(w, err) {
|
||||
if h.handleErr(w, r, err) {
|
||||
return
|
||||
}
|
||||
views := make([]apiKeyView, 0, len(keys))
|
||||
@@ -51,7 +51,7 @@ func (h *Handler) CreateAPIKey(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
plaintext, row, err := h.store.CreateAPIKey(r.Context(), in, auth.UserFrom(r.Context()))
|
||||
if h.handleErr(w, err) {
|
||||
if h.handleErr(w, r, err) {
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, map[string]any{
|
||||
@@ -63,7 +63,7 @@ func (h *Handler) CreateAPIKey(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// RevokeAPIKey disables a key. Subsequent requests with it are rejected.
|
||||
func (h *Handler) RevokeAPIKey(w http.ResponseWriter, r *http.Request) {
|
||||
if err := h.store.RevokeAPIKey(r.Context(), chi.URLParam(r, "id")); h.handleErr(w, err) {
|
||||
if err := h.store.RevokeAPIKey(r.Context(), chi.URLParam(r, "id")); h.handleErr(w, r, err) {
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"status": "revoked"})
|
||||
|
||||
Reference in New Issue
Block a user