diff --git a/drip/api.gen.go b/drip/api.gen.go index ead83b4..57cfa80 100644 --- a/drip/api.gen.go +++ b/drip/api.gen.go @@ -3607,6 +3607,15 @@ func (response ListAllNodeVersions200JSONResponse) VisitListAllNodeVersionsRespo return json.NewEncoder(w).Encode(response) } +type ListAllNodeVersions400JSONResponse ErrorResponse + +func (response ListAllNodeVersions400JSONResponse) VisitListAllNodeVersionsResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + type ListAllNodeVersions403JSONResponse ErrorResponse func (response ListAllNodeVersions403JSONResponse) VisitListAllNodeVersionsResponse(w http.ResponseWriter) error { @@ -4995,9 +5004,9 @@ var swaggerSpec = []string{ "ao2xqljDHSqTqxmUg3Pwo8s6X4Apo5mantV83mHxr2ICdJF3o/DyrqcY3yFxwc0Tew90863gezb7/S+r", "vjfRrs/2dvU4kXdIeN4cV8oRTFP7gtXQ2TzXS9XzTcu3lN3Htm6fttz0py1rF4mGCwbvEHtVFTFVtZcU", "Fmn4RMrYnU5/JbrOUxWNrD2Sj15YRMqFRSp/kOQXPWCdkW2R/ztL0rtVGC2n37NoauWSLDcG2J6Yg5e7", - "u8O7VjJ1vJ6PWNF0ELlUfw/1a3qoMRtb0WZzS8vUEUSzc04zJDUtYYpIB6KcrDKtn+Mc3dh/n6l/L3m2", - "/rda514XVk34G/PIn9Y6f6YTsxj/m/EZbijRj3h/ZIZ/fjVdjN9Ov+13q/VdCUAjScHSaC+aC5HzvdEI", - "5nio/JJDymbR7Zfb/w8AAP//IbFMgHbCAAA=", + "u8O7VjJ1vJ6PWNF0ELlUfw/1a3qoMUsq2jzdW5G+yqtPV19ncwvd1NFVCxdOMyT1PmFKWgdirqxqrx8H", + "Hd3Yf5+pfy95RP+3Wude12dN+Bvz5KDWgX+mE7MY/wv2GW6o9I94m2WGf34VZowXUb80eKu1bwlAI0nB", + "0mgvmguR873RCOZ4qLykQ8pm0e2X2/8PAAD//+q2rNUEwwAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/openapi.yml b/openapi.yml index 3eab30f..a0486b2 100644 --- a/openapi.yml +++ b/openapi.yml @@ -82,10 +82,10 @@ paths: format: int64 description: The end time of the job as a Unix timestamp. avg_vram: - type: integer + type: integer description: The average amount of VRAM used in the run. peak_vram: - type: integer + type: integer description: The peak amount of VRAM used in the run. pr_number: type: string @@ -1639,7 +1639,12 @@ paths: totalPages: type: integer description: Total number of pages available - + '400': + description: Invalid input, object invalid + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorResponse' '403': description: Node banned content: @@ -1677,7 +1682,7 @@ paths: required: true content: application/json: - schema: + schema: type: object properties: status: @@ -1760,7 +1765,7 @@ paths: schema: $ref: '#/components/schemas/ErrorResponse' /nodes/{nodeId}/versions/{version}/comfy-nodes: - post: + post: summary: create comfy-nodes for certain node operationId: CreateComfyNodes tags: @@ -1780,7 +1785,7 @@ paths: required: true content: application/json: - schema: + schema: type: object properties: nodes: @@ -1899,7 +1904,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ErrorResponse' + $ref: '#/components/schemas/ErrorResponse' components: schemas: PersonalAccessToken: @@ -2059,7 +2064,7 @@ components: git_repo: type: string description: The repository name - pr_number: + pr_number: type: string description: The pull request number start_time: @@ -2079,12 +2084,12 @@ components: job_trigger_user: type: string description: The user who triggered the job. - author: + author: type: string description: The author of the commit machine_stats: $ref: "#/components/schemas/MachineStats" - status: + status: $ref: "#/components/schemas/WorkflowRunStatus" storage_file: $ref: "#/components/schemas/StorageFile" @@ -2224,7 +2229,7 @@ components: type: string description: The reason for the status change. comfy_nodes: - type: object + type: object additionalProperties: $ref: "#/components/schemas/ComfyNode" node_id: diff --git a/server/implementation/registry.go b/server/implementation/registry.go index 626b1da..9b77d45 100644 --- a/server/implementation/registry.go +++ b/server/implementation/registry.go @@ -3,6 +3,7 @@ package implementation import ( "context" "errors" + "fmt" "registry-backend/drip" "registry-backend/ent" "registry-backend/ent/publisher" @@ -954,16 +955,29 @@ func (s *DripStrictServerImplementation) SecurityScan( func (s *DripStrictServerImplementation) ListAllNodeVersions( ctx context.Context, request drip.ListAllNodeVersionsRequestObject) (drip.ListAllNodeVersionsResponseObject, error) { - log.Ctx(ctx).Info().Msg("ListAllNodeVersions request received") + log.Ctx(ctx).Info().Msgf("ListAllNodeVersions request received %+v", request.Params) + // Default values for pagination page := 1 if request.Params.Page != nil { page = *request.Params.Page } + pageSize := 10 - if request.Params.PageSize != nil && *request.Params.PageSize < 100 { + maxPageSize := 100 + if request.Params.PageSize != nil { + // Validate pageSize + if *request.Params.PageSize > maxPageSize { + log.Ctx(ctx).Error().Msgf( + "Requested pageSize %d exceeds maximum allowed %d", *request.Params.PageSize, maxPageSize) + return drip.ListAllNodeVersions400JSONResponse{ + Message: fmt.Sprintf( + "Invalid pageSize: %d. The maximum allowed is %d.", *request.Params.PageSize, maxPageSize), + }, nil + } pageSize = *request.Params.PageSize } + f := &drip_services.NodeVersionFilter{ Page: page, PageSize: pageSize, @@ -974,15 +988,22 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions( f.Status = mapper.ApiNodeVersionStatusesToDbNodeVersionStatuses(request.Params.Statuses) } + // Log the constructed filter + log.Ctx(ctx).Info().Msgf("Constructed Filter: %+v", f) + // List nodes from the registry service nodeVersionResults, err := s.RegistryService.ListNodeVersions(ctx, s.Client, f) if err != nil { log.Ctx(ctx).Error().Msgf("Failed to list node versions w/ err: %v", err) - return drip.ListAllNodeVersions500JSONResponse{Message: "Failed to list node versions", Error: err.Error()}, nil + return drip.ListAllNodeVersions500JSONResponse{ + Message: "Failed to list node versions", + Error: err.Error(), + }, nil } + // Handle no results if len(nodeVersionResults.NodeVersions) == 0 { - log.Ctx(ctx).Info().Msg("No node versions found") + log.Ctx(ctx).Info().Msgf("No node versions found. Total: %d", nodeVersionResults.Total) return drip.ListAllNodeVersions200JSONResponse{ Versions: &[]drip.NodeVersion{}, Total: &nodeVersionResults.Total, @@ -992,12 +1013,15 @@ func (s *DripStrictServerImplementation) ListAllNodeVersions( }, nil } + // Transform DB results into API results apiNodeVersions := make([]drip.NodeVersion, 0, len(nodeVersionResults.NodeVersions)) for _, dbNodeVersion := range nodeVersionResults.NodeVersions { apiNodeVersions = append(apiNodeVersions, *mapper.DbNodeVersionToApiNodeVersion(dbNodeVersion)) } - log.Ctx(ctx).Info().Msgf("Found %d node versions", nodeVersionResults.Total) + // Log success + log.Ctx(ctx).Info().Msgf( + "Found %d node versions. Total: %d", len(nodeVersionResults.NodeVersions), nodeVersionResults.Total) return drip.ListAllNodeVersions200JSONResponse{ Versions: &apiNodeVersions, Total: &nodeVersionResults.Total,