MCPcopy Index your code
hub / github.com/tbphp/gpt-load / ExportKeys

Method ExportKeys

internal/handler/key_handler.go:469–499  ·  view source on GitHub ↗

ExportKeys handles exporting keys to a text file.

(c *gin.Context)

Source from the content-addressed store, hash-verified

467
468// ExportKeys handles exporting keys to a text file.
469func (s *Server) ExportKeys(c *gin.Context) {
470 groupID, ok := validateGroupIDFromQuery(c)
471 if !ok {
472 return
473 }
474
475 statusFilter := c.Query("status")
476 if statusFilter == "" {
477 statusFilter = "all"
478 }
479
480 switch statusFilter {
481 case "all", models.KeyStatusActive, models.KeyStatusInvalid:
482 default:
483 response.ErrorI18nFromAPIError(c, app_errors.ErrValidation, "validation.invalid_status_filter")
484 return
485 }
486
487 group, ok := s.findGroupByID(c, groupID)
488 if !ok {
489 return
490 }
491
492 filename := fmt.Sprintf("keys-%s-%s.txt", group.Name, statusFilter)
493 c.Header("Content-Disposition", "attachment; filename="+filename)
494 c.Header("Content-Type", "text/plain; charset=utf-8")
495
496 if err := s.KeyService.StreamKeysToWriter(groupID, statusFilter, c.Writer); err != nil {
497 log.Printf("Failed to stream keys: %v", err)
498 }
499}
500
501// UpdateKeyNotesRequest defines the payload for updating a key's notes.
502type UpdateKeyNotesRequest struct {

Callers

nothing calls this directly

Calls 4

findGroupByIDMethod · 0.95
ErrorI18nFromAPIErrorFunction · 0.92
validateGroupIDFromQueryFunction · 0.85
StreamKeysToWriterMethod · 0.80

Tested by

no test coverage detected