ExportKeys handles exporting keys to a text file.
(c *gin.Context)
| 467 | |
| 468 | // ExportKeys handles exporting keys to a text file. |
| 469 | func (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. |
| 502 | type UpdateKeyNotesRequest struct { |
nothing calls this directly
no test coverage detected