Skip to content

Commit aea4513

Browse files
committed
feat(add): updated artifacts logic
1 parent a11fb69 commit aea4513

2 files changed

Lines changed: 46 additions & 27 deletions

File tree

internal/handlers/artifacts.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,16 @@ func GetArtifacts(c *fiber.Ctx) error {
5454
query.Limit = limit
5555
query.Offset = offset
5656

57-
artifacts, err := artifactsService.GetArtifacts(query)
57+
result, err := artifactsService.GetArtifacts(query)
5858
if err != nil {
5959
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
6060
"error": err.Error(),
6161
"status": fiber.StatusInternalServerError,
6262
})
6363
}
6464

65-
// Calculate total (assuming all artifacts match without offset)
66-
total := len(artifacts) + offset
67-
if len(artifacts) < limit {
68-
total = offset + len(artifacts)
69-
}
65+
artifacts := result.Data
66+
totalFiltered := result.Total
7067

7168
// Get unique platforms and support statuses for metadata
7269
platformsMap := make(map[string]bool)
@@ -88,10 +85,10 @@ func GetArtifacts(c *fiber.Ctx) error {
8885
return c.JSON(fiber.Map{
8986
"data": artifacts,
9087
"metadata": fiber.Map{
91-
"total": total,
88+
"total": totalFiltered,
9289
"limit": limit,
9390
"offset": offset,
94-
"hasMore": len(artifacts) == limit,
91+
"hasMore": offset+len(artifacts) < totalFiltered,
9592
"platforms": platforms,
9693
"supportStatuses": statuses,
9794
"query": fiber.Map{
@@ -133,23 +130,23 @@ func GetArtifactByVersion(c *fiber.Ctx) error {
133130
IncludeEOL: true,
134131
}
135132

136-
artifacts, err := artifactsService.GetArtifacts(query)
133+
result, err := artifactsService.GetArtifacts(query)
137134
if err != nil {
138135
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
139136
"error": err.Error(),
140137
})
141138
}
142139

143-
if len(artifacts) == 0 {
140+
if len(result.Data) == 0 {
144141
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
145142
"error": "Artifact version not found",
146143
})
147144
}
148145

149146
return c.JSON(fiber.Map{
150147
"success": true,
151-
"count": len(artifacts),
152-
"data": artifacts,
148+
"count": len(result.Data),
149+
"data": result.Data,
153150
})
154151
}
155152

@@ -176,14 +173,14 @@ func CheckArtifact(c *fiber.Ctx) error {
176173
IncludeEOL: true,
177174
}
178175

179-
artifacts, err := artifactsService.GetArtifacts(query)
176+
result, err := artifactsService.GetArtifacts(query)
180177
if err != nil {
181178
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
182179
"error": err.Error(),
183180
})
184181
}
185182

186-
if len(artifacts) == 0 {
183+
if len(result.Data) == 0 {
187184
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
188185
"error": "Artifact version not found",
189186
"version": version,
@@ -194,8 +191,8 @@ func CheckArtifact(c *fiber.Ctx) error {
194191
"success": true,
195192
"version": version,
196193
"available": true,
197-
"platformCount": len(artifacts),
198-
"platforms": artifacts,
194+
"platformCount": len(result.Data),
195+
"platforms": result.Data,
199196
})
200197
}
201198

@@ -223,15 +220,15 @@ func GetArtifactChanges(c *fiber.Ctx) error {
223220
baseQuery := services.ArtifactsQuery{Version: base, IncludeEOL: true}
224221
headQuery := services.ArtifactsQuery{Version: head, IncludeEOL: true}
225222

226-
baseArtifacts, err := artifactsService.GetArtifacts(baseQuery)
227-
if err != nil || len(baseArtifacts) == 0 {
223+
baseResult, err := artifactsService.GetArtifacts(baseQuery)
224+
if err != nil || len(baseResult.Data) == 0 {
228225
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
229226
"error": "Base version not found",
230227
})
231228
}
232229

233-
headArtifacts, err := artifactsService.GetArtifacts(headQuery)
234-
if err != nil || len(headArtifacts) == 0 {
230+
headResult, err := artifactsService.GetArtifacts(headQuery)
231+
if err != nil || len(headResult.Data) == 0 {
235232
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
236233
"error": "Head version not found",
237234
})
@@ -243,11 +240,11 @@ func GetArtifactChanges(c *fiber.Ctx) error {
243240
"base": base,
244241
"head": head,
245242
"comparison": map[string]interface{}{
246-
"base_hash": baseArtifacts[0].Hash,
247-
"head_hash": headArtifacts[0].Hash,
248-
"base_date": baseArtifacts[0].Date,
249-
"head_date": headArtifacts[0].Date,
250-
"platforms": len(headArtifacts),
243+
"base_hash": baseResult.Data[0].Hash,
244+
"head_hash": headResult.Data[0].Hash,
245+
"base_date": baseResult.Data[0].Date,
246+
"head_date": headResult.Data[0].Date,
247+
"platforms": len(headResult.Data),
251248
},
252249
"message": "Use GitHub API to fetch detailed commit history",
253250
})

internal/services/artifacts.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type ArtifactsQuery struct {
7979

8080
type ArtifactEntry struct {
8181
Version string
82+
FullVersion string // Full version string like v1.0.0.12345 for Pterodactyl
8283
Hash string
8384
Platform PlatformType
8485
Date string
@@ -87,6 +88,13 @@ type ArtifactEntry struct {
8788
Size int64
8889
}
8990

91+
// ArtifactsResult holds paginated results with metadata
92+
type ArtifactsResult struct {
93+
Data []ArtifactEntry
94+
Total int
95+
FilteredBy string
96+
}
97+
9098
// Cache structures
9199
type cacheEntry struct {
92100
data interface{}
@@ -371,7 +379,7 @@ func (s *ArtifactsService) PaginateArtifacts(artifacts []ArtifactEntry, limit, o
371379
}
372380

373381
// GetArtifacts returns the full list of artifacts with filtering and pagination
374-
func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) ([]ArtifactEntry, error) {
382+
func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) (*ArtifactsResult, error) {
375383
tags, err := s.FetchGitHubTags(true)
376384
if err != nil {
377385
return nil, err
@@ -384,6 +392,7 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) ([]ArtifactEntry,
384392
for version, artifact := range processedData.Windows {
385393
artifacts = append(artifacts, ArtifactEntry{
386394
Version: version,
395+
FullVersion: s.generateFullVersion(version),
387396
Hash: artifact.Hash,
388397
Platform: Windows,
389398
Date: artifact.Date,
@@ -395,6 +404,7 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) ([]ArtifactEntry,
395404
for version, artifact := range processedData.Linux {
396405
artifacts = append(artifacts, ArtifactEntry{
397406
Version: version,
407+
FullVersion: s.generateFullVersion(version),
398408
Hash: artifact.Hash,
399409
Platform: Linux,
400410
Date: artifact.Date,
@@ -407,6 +417,9 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) ([]ArtifactEntry,
407417
// Apply filtering
408418
filtered := s.FilterArtifacts(artifacts, query)
409419

420+
// Store total count after filtering but before pagination
421+
totalFiltered := len(filtered)
422+
410423
// Apply sorting
411424
sorted := s.SortArtifacts(filtered, query.SortBy, query.SortOrder)
412425

@@ -416,7 +429,10 @@ func (s *ArtifactsService) GetArtifacts(query ArtifactsQuery) ([]ArtifactEntry,
416429
}
417430
paginated := s.PaginateArtifacts(sorted, query.Limit, query.Offset)
418431

419-
return paginated, nil
432+
return &ArtifactsResult{
433+
Data: paginated,
434+
Total: totalFiltered,
435+
}, nil
420436
}
421437

422438
// Helper methods
@@ -447,6 +463,12 @@ func (s *ArtifactsService) determineSupportStatus(version int) SupportStatus {
447463
}
448464
}
449465

466+
// generateFullVersion creates the full version string for hosting panels like Pterodactyl
467+
// Format: v1.0.0.{build_number} (e.g., v1.0.0.12345)
468+
func (s *ArtifactsService) generateFullVersion(version string) string {
469+
return fmt.Sprintf("v1.0.0.%s", version)
470+
}
471+
450472
func (s *ArtifactsService) estimateSize(version string, platform string) int64 {
451473
// Rough estimates in MB
452474
if platform == "windows" {

0 commit comments

Comments
 (0)