Skip to content

Commit 2696cb1

Browse files
committed
fix: even more stuff yes
1 parent 23c2fae commit 2696cb1

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Format: `{version}-{hash}` (e.g., `24769-315823736cfbc085104ca0d32779311cd2f1a5a8`)
3333
- Compatible with Pterodactyl, Pelican, and similar hosting panel egg configurations
3434

35+
- **Artifact statistics in API response** - Added `stats` object to metadata
36+
- Includes counts for: `total`, `recommended`, `latest`, `active`, `deprecated`, `eol`
37+
- Calculated from filtered results before pagination
38+
- Enables frontend to show accurate totals regardless of current page
39+
3540
### Fixed
3641
- **Pagination total count** - Fixed incorrect total count in pagination metadata
3742
- Previously returned count of paginated results instead of total filtered results
@@ -41,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4146
### Changed
4247
- Updated all artifact handlers to use new `ArtifactsResult` return type
4348
- Refactored `generateFullVersion()` helper to accept hash parameter
49+
- Added `ArtifactStats` struct and `calculateStats()` helper function
4450

4551
---
4652

internal/handlers/artifacts.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ func GetArtifacts(c *fiber.Ctx) error {
9191
"hasMore": offset+len(artifacts) < totalFiltered,
9292
"platforms": platforms,
9393
"supportStatuses": statuses,
94+
"stats": fiber.Map{
95+
"total": result.Stats.Total,
96+
"recommended": result.Stats.Recommended,
97+
"latest": result.Stats.Latest,
98+
"active": result.Stats.Active,
99+
"deprecated": result.Stats.Deprecated,
100+
"eol": result.Stats.EOL,
101+
},
94102
"query": fiber.Map{
95103
"platform": query.Platform,
96104
"version": query.Version,

internal/services/artifacts.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,21 @@ type ArtifactEntry struct {
8888
Size int64
8989
}
9090

91+
// ArtifactStats holds counts by support status
92+
type ArtifactStats struct {
93+
Total int `json:"total"`
94+
Recommended int `json:"recommended"`
95+
Latest int `json:"latest"`
96+
Active int `json:"active"`
97+
Deprecated int `json:"deprecated"`
98+
EOL int `json:"eol"`
99+
}
100+
91101
// ArtifactsResult holds paginated results with metadata
92102
type ArtifactsResult struct {
93103
Data []ArtifactEntry
94104
Total int
105+
Stats ArtifactStats
95106
FilteredBy string
96107
}
97108

@@ -420,6 +431,9 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) (*ArtifactsResult,
420431
// Store total count after filtering but before pagination
421432
totalFiltered := len(filtered)
422433

434+
// Calculate stats from filtered results (before pagination)
435+
stats := s.calculateStats(filtered)
436+
423437
// Apply sorting
424438
sorted := s.SortArtifacts(filtered, query.SortBy, query.SortOrder)
425439

@@ -432,6 +446,7 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) (*ArtifactsResult,
432446
return &ArtifactsResult{
433447
Data: paginated,
434448
Total: totalFiltered,
449+
Stats: stats,
435450
}, nil
436451
}
437452

@@ -469,6 +484,28 @@ func (s *ArtifactsService) generateFullVersion(version string, hash string) stri
469484
return fmt.Sprintf("%s-%s", version, hash)
470485
}
471486

487+
// calculateStats calculates artifact counts by support status
488+
func (s *ArtifactsService) calculateStats(artifacts []ArtifactEntry) ArtifactStats {
489+
stats := ArtifactStats{
490+
Total: len(artifacts),
491+
}
492+
for _, artifact := range artifacts {
493+
switch artifact.SupportStatus {
494+
case Recommended:
495+
stats.Recommended++
496+
case Latest:
497+
stats.Latest++
498+
case Active:
499+
stats.Active++
500+
case Deprecated:
501+
stats.Deprecated++
502+
case EOL:
503+
stats.EOL++
504+
}
505+
}
506+
return stats
507+
}
508+
472509
func (s *ArtifactsService) estimateSize(version string, platform string) int64 {
473510
// Rough estimates in MB
474511
if platform == "windows" {

0 commit comments

Comments
 (0)