ListImages handles GET /docker/images.
(w http.ResponseWriter, r *http.Request)
| 146 | |
| 147 | // ListImages handles GET /docker/images. |
| 148 | func (h *DockerHandler) ListImages(w http.ResponseWriter, r *http.Request) { |
| 149 | q := r.URL.Query() |
| 150 | page := parseIntQuery(r, "page", 1) |
| 151 | limit := parseIntQuery(r, "limit", 50) |
| 152 | search := q.Get("search") |
| 153 | if len(search) > 200 { |
| 154 | search = search[:200] |
| 155 | } |
| 156 | params := store.ImageListParams{ |
| 157 | Source: q.Get("source"), |
| 158 | Search: search, |
| 159 | Page: page, |
| 160 | Limit: limit, |
| 161 | } |
| 162 | images, total, err := h.docker.ListImages(r.Context(), params) |
| 163 | if err != nil { |
| 164 | Error(w, http.StatusInternalServerError, "Failed to fetch images") |
| 165 | return |
| 166 | } |
| 167 | pages := (total + params.Limit - 1) / params.Limit |
| 168 | if pages < 1 { |
| 169 | pages = 1 |
| 170 | } |
| 171 | // Build response with _count for frontend compatibility |
| 172 | imgResp := make([]map[string]interface{}, len(images)) |
| 173 | for i, img := range images { |
| 174 | imgResp[i] = map[string]interface{}{ |
| 175 | "id": img.ID, |
| 176 | "repository": img.Repository, |
| 177 | "tag": img.Tag, |
| 178 | "image_id": img.ImageID, |
| 179 | "digest": img.Digest, |
| 180 | "size_bytes": img.SizeBytes, |
| 181 | "source": img.Source, |
| 182 | "created_at": img.CreatedAt, |
| 183 | "last_pulled": img.LastPulled, |
| 184 | "last_checked": img.LastChecked, |
| 185 | "updated_at": img.UpdatedAt, |
| 186 | "hasUpdates": img.HasUpdates, |
| 187 | "_count": map[string]interface{}{"docker_containers": img.CountContainers}, |
| 188 | } |
| 189 | } |
| 190 | JSON(w, http.StatusOK, map[string]interface{}{ |
| 191 | "images": imgResp, |
| 192 | "pagination": map[string]interface{}{ |
| 193 | "page": page, |
| 194 | "limit": params.Limit, |
| 195 | "total": total, |
| 196 | "totalPages": pages, |
| 197 | }, |
| 198 | }) |
| 199 | } |
| 200 | |
| 201 | // GetImage handles GET /docker/images/:id. |
| 202 | func (h *DockerHandler) GetImage(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected