Skip to content

Modern Docker Management, Designed for Everyone

fix: use dedicated endpoint for totalImageSize

Kyle Mendell58edb08bdda3
diff --git a/backend/internal/api/environment_handler.go b/backend/internal/api/environment_handler.go
index 439614823..4ded57be2 100644
--- a/backend/internal/api/environment_handler.go
+++ b/backend/internal/api/environment_handler.go
@@ -128,6 +128,9 @@ func (h *EnvironmentHandler) handleImageEndpoints(c *gin.Context, endpoint strin
case endpoint == "/images" && c.Request.Method == http.MethodGet:
imageHandler.List(c)
return true
+ case endpoint == "/images/total-size" && c.Request.Method == http.MethodGet:
+ imageHandler.GetTotalSize(c)
+ return true
case endpoint == "/images/pull" && c.Request.Method == http.MethodPost:
imageHandler.Pull(c)
return true
@@ -629,6 +632,10 @@ func (h *EnvironmentHandler) GetImage(c *gin.Context) {
h.routeRequest(c, "/images/"+imageID)
}
+func (h *EnvironmentHandler) GetTotalImageSize(c *gin.Context) {
+ h.routeRequest(c, "/images/total-size")
+}
+
func (h *EnvironmentHandler) RemoveImage(c *gin.Context) {
imageID := c.Param("imageId")
h.routeRequest(c, "/images/"+imageID)
diff --git a/backend/internal/api/image_handler.go b/backend/internal/api/image_handler.go
index 2859bff8e..3d7894487 100644
--- a/backend/internal/api/image_handler.go
+++ b/backend/internal/api/image_handler.go
@@ -187,3 +187,23 @@ func (h *ImageHandler) GetHistory(c *gin.Context) {
"data": history,
})
}
+
+func (h *ImageHandler) GetTotalSize(c *gin.Context) {
+ ctx := c.Request.Context()
+
+ total, err := h.imageService.GetTotalImageSize(ctx)
+ if err != nil {
+ c.JSON(http.StatusInternalServerError, gin.H{
+ "success": false,
+ "error": err.Error(),
+ })
+ return
+ }
+
+ c.JSON(http.StatusOK, gin.H{
+ "success": true,
+ "data": gin.H{
+ "totalSize": total,
+ },
+ })
+}
diff --git a/backend/internal/api/routes.go b/backend/internal/api/routes.go
index 6894fcbce..426704377 100644
--- a/backend/internal/api/routes.go
+++ b/backend/internal/api/routes.go
@@ -77,6 +77,7 @@ func setupImageUpdateRoutes(api *gin.RouterGroup, services *Services) {
imageUpdates.GET("/summary", imageUpdateHandler.GetUpdateSummary)
imageUpdates.GET("/versions", imageUpdateHandler.GetImageVersions)
imageUpdates.POST("/compare", imageUpdateHandler.CompareVersions)
+
}
func setupOidcRoutes(api *gin.RouterGroup, services *Services, appConfig *config.Config) {
@@ -187,6 +188,7 @@ func setupEnvironmentRoutes(api *gin.RouterGroup, services *Services) {
environments.DELETE("/:id/images/:imageId", environmentHandler.RemoveImage)
environments.POST("/:id/images/pull", environmentHandler.PullImage)
environments.POST("/:id/images/prune", environmentHandler.PruneImages)
+ environments.GET("/:id/images/total-size", environmentHandler.GetTotalImageSize)
environments.GET("/:id/networks", environmentHandler.GetNetworks)
environments.POST("/:id/networks", environmentHandler.CreateNetwork)
@@ -296,6 +298,7 @@ func setupImageRoutes(api *gin.RouterGroup, services *Services) {
images.POST("/pull", imageHandler.Pull)
images.POST("/prune", imageHandler.Prune)
images.GET("/:id/history", imageHandler.GetHistory)
+ images.GET("/total-size", imageHandler.GetTotalSize)
}
func setupVolumeRoutes(api *gin.RouterGroup, services *Services) {
diff --git a/backend/internal/services/image_service.go b/backend/internal/services/image_service.go
index 954be7ecb..03640d304 100644
--- a/backend/internal/services/image_service.go
+++ b/backend/internal/services/image_service.go
@@ -605,6 +605,19 @@ func (s *ImageService) ListImagesWithUpdatesPaginated(ctx context.Context, req u
return result, pagination, nil
}
+func (s *ImageService) GetTotalImageSize(ctx context.Context) (int64, error) {
+ images, err := s.ListImages(ctx)
+ if err != nil {
+ return 0, fmt.Errorf("failed to list images: %w", err)
+ }
+
+ var total int64
+ for _, img := range images {
+ total += img.Size
+ }
+ return total, nil
+}
+
func (s *ImageService) CleanupOrphanedUpdateRecords(ctx context.Context, existingImageIDs []string) (int64, error) {
var result *gorm.DB
if len(existingImageIDs) == 0 {
diff --git a/frontend/src/lib/services/api/api-service.ts b/frontend/src/lib/services/api/api-service.ts
index dce748f14..180b77dad 100644
--- a/frontend/src/lib/services/api/api-service.ts
+++ b/frontend/src/lib/services/api/api-service.ts
@@ -45,7 +45,12 @@ abstract class BaseAPIService {
const response = await promise;
- const extractedData = response.data || response.data.data;
+ // Prefer nested "data" payloads when present
+ const payload = response.data;
+ const extractedData =
+ payload && typeof payload === 'object' && 'data' in payload && payload.data !== undefined
+ ? payload.data
+ : payload;
return extractedData;
}
diff --git a/frontend/src/lib/services/api/environment-api-service.ts b/frontend/src/lib/services/api/environment-api-service.ts
index a1250a22f..e5518e821 100644
--- a/frontend/src/lib/services/api/environment-api-service.ts
+++ b/frontend/src/lib/services/api/environment-api-service.ts
@@ -160,6 +160,21 @@ export class EnvironmentAPIService extends BaseAPIService {
return this.handleResponse(this.api.get(`/environments/${envId}/images`, { params }));
}
+ async getTotalImageSize(): Promise<number> {
+ const envId = await this.getCurrentEnvironmentId();
+ const res = await this.handleResponse<any>(
+ this.api.get(`/environments/${envId}/images/total-size`)
+ );
+ // Support both shapes just in case
+ if (typeof res === 'number') return res;
+ if (res && typeof res === 'object') {
+ if ('totalSize' in res && typeof res.totalSize === 'number') return res.totalSize;
+ if ('data' in res && res.data && typeof res.data.totalSize === 'number')
+ return res.data.totalSize;
+ }
+ return 0;
+ }
+
async getImage(imageId: string): Promise<any> {
const envId = await this.getCurrentEnvironmentId();
return this.handleResponse(this.api.get(`/environments/${envId}/images/${imageId}`));
diff --git a/frontend/src/lib/services/api/image-api-service.ts b/frontend/src/lib/services/api/image-api-service.ts
index aeb745475..a5df4549d 100644
--- a/frontend/src/lib/services/api/image-api-service.ts
+++ b/frontend/src/lib/services/api/image-api-service.ts
@@ -1,186 +1,190 @@
import BaseAPIService from './api-service';
-import type { PaginationRequest, SortRequest, PaginatedApiResponse } from '$lib/types/pagination.type';
+import type {
+ PaginationRequest,
+ SortRequest,
+ PaginatedApiResponse
+} from '$lib/types/pagination.type';
export default class ImageAPIService extends BaseAPIService {
- async list(filters?: Record<string, string>) {
- return this.handleResponse(this.api.get('/images', { params: { filters } }));
- }
-
- async listPaginated(
- pagination: PaginationRequest,
- sort?: SortRequest,
- filters?: Record<string, string>
- ): Promise<PaginatedApiResponse<any>> {
- const params: any = {
- page: pagination.page,
- limit: pagination.limit
- };
-
- if (sort) {
- params.column = sort.column;
- params.direction = sort.direction;
- }
-
- if (filters) {
- params.filters = filters;
- }
-
- return this.handleResponse(this.api.get('/images', { params }));
- }
-
- async get(id: string) {
- return this.handleResponse(this.api.get(`/images/${id}`));
- }
-
- async inspect(id: string) {
- return this.handleResponse(this.api.get(`/images/${id}/inspect`));
- }
-
- async search(term: string, limit?: number) {
- return this.handleResponse(
- this.api.get('/images/search', {
- params: { term, limit }
- })
- );
- }
-
- async pull(imageName: string, tag: string = 'latest', auth?: any) {
- return this.handleResponse(
- this.api.post('/images/pull', {
- imageName,
- tag,
- auth
- })
- );
- }
-
- async push(imageName: string, tag: string = 'latest', auth?: any) {
- return this.handleResponse(
- this.api.post('/images/push', {
- imageName,
- tag,
- auth
- })
- );
- }
-
- async remove(id: string, options?: { force?: boolean; noprune?: boolean }) {
- return this.handleResponse(
- this.api.delete(`/images/${id}`, {
- params: options
- })
- );
- }
-
- async tag(id: string, repo: string, tag: string) {
- return this.handleResponse(
- this.api.post(`/images/${id}/tag`, {
- repo,
- tag
- })
- );
- }
-
- async history(id: string) {
- return this.handleResponse(this.api.get(`/images/${id}/history`));
- }
-
- async prune(filters?: Record<string, string>) {
- return this.handleResponse(this.api.post('/images/prune', { filters }));
- }
-
- async build(
- context: FormData,
- options?: {
- dockerfile?: string;
- tags?: string[];
- buildArgs?: Record<string, string>;
- target?: string;
- networkMode?: string;
- platform?: string;
- }
- ) {
- return this.handleResponse(
- this.api.post('/images/build', context, {
- headers: {
- 'Content-Type': 'multipart/form-data'
- },
- params: options
- })
- );
- }
-
- async export(ids: string[]) {
- const response = await this.api.post(
- '/images/export',
- { ids },
- {
- responseType: 'blob'
- }
- );
- return response.data;
- }
-
- async import(source: File | string, repo?: string, tag?: string) {
- const formData = new FormData();
- if (source instanceof File) {
- formData.append('file', source);
- } else {
- formData.append('url', source);
- }
- if (repo) formData.append('repo', repo);
- if (tag) formData.append('tag', tag);
-
- return this.handleResponse(
- this.api.post('/images/import', formData, {
- headers: {
- 'Content-Type': 'multipart/form-data'
- }
- })
- );
- }
-
- async commit(
- containerId: string,
- options?: {
- repo?: string;
- tag?: string;
- comment?: string;
- author?: string;
- pause?: boolean;
- changes?: string[];
- }
- ) {
- return this.handleResponse(
- this.api.post('/images/commit', {
- containerId,
- ...options
- })
- );
- }
-
- async checkMaturity(imageId: string) {
- return this.handleResponse(this.api.get(`/images/maturity/${imageId}`));
- }
-
- async checkMaturityBatch(imageIds: string[]) {
- if (!imageIds || imageIds.length === 0) {
- throw new Error('No image IDs provided for batch check');
- }
-
- const firstId = imageIds[0];
- return this.handleResponse(this.api.post(`/images/${firstId}/maturity`, { imageIds }));
- }
-
- async updateMaturity(imageId: string, maturityData: any) {
- return this.handleResponse(this.api.put(`/images/maturity/${imageId}`, maturityData));
- }
-
- async getVulnerabilities(imageId: string) {
- return this.handleResponse(this.api.get(`/images/${imageId}/vulnerabilities`));
- }
-
- async scanImage(imageId: string) {
- return this.handleResponse(this.api.post(`/images/${imageId}/scan`));
- }
+ async list(filters?: Record<string, string>) {
+ return this.handleResponse(this.api.get('/images', { params: { filters } }));
+ }
+
+ async listPaginated(
+ pagination: PaginationRequest,
+ sort?: SortRequest,
+ filters?: Record<string, string>
+ ): Promise<PaginatedApiResponse<any>> {
+ const params: any = {
+ page: pagination.page,
+ limit: pagination.limit
+ };
+
+ if (sort) {
+ params.column = sort.column;
+ params.direction = sort.direction;
+ }
+
+ if (filters) {
+ params.filters = filters;
+ }
+
+ return this.handleResponse(this.api.get('/images', { params }));
+ }
+
+ async getTotalSize() {
+ return this.handleResponse(this.api.get(`/images/total-size`));
+ }
+
+ async inspect(id: string) {
+ return this.handleResponse(this.api.get(`/images/${id}/inspect`));
+ }
+
+ async search(term: string, limit?: number) {
+ return this.handleResponse(
+ this.api.get('/images/search', {
+ params: { term, limit }
+ })
+ );
+ }
+
+ async pull(imageName: string, tag: string = 'latest', auth?: any) {
+ return this.handleResponse(
+ this.api.post('/images/pull', {
+ imageName,
+ tag,
+ auth
+ })
+ );
+ }
+
+ async push(imageName: string, tag: string = 'latest', auth?: any) {
+ return this.handleResponse(
+ this.api.post('/images/push', {
+ imageName,
+ tag,
+ auth
+ })
+ );
+ }
+
+ async remove(id: string, options?: { force?: boolean; noprune?: boolean }) {
+ return this.handleResponse(
+ this.api.delete(`/images/${id}`, {
+ params: options
+ })
+ );
+ }
+
+ async tag(id: string, repo: string, tag: string) {
+ return this.handleResponse(
+ this.api.post(`/images/${id}/tag`, {
+ repo,
+ tag
+ })
+ );
+ }
+
+ async history(id: string) {
+ return this.handleResponse(this.api.get(`/images/${id}/history`));
+ }
+
+ async prune(filters?: Record<string, string>) {
+ return this.handleResponse(this.api.post('/images/prune', { filters }));
+ }
+
+ async build(
+ context: FormData,
+ options?: {
+ dockerfile?: string;
+ tags?: string[];
+ buildArgs?: Record<string, string>;
+ target?: string;
+ networkMode?: string;
+ platform?: string;
+ }
+ ) {
+ return this.handleResponse(
+ this.api.post('/images/build', context, {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ },
+ params: options
+ })
+ );
+ }
+
+ async export(ids: string[]) {
+ const response = await this.api.post(
+ '/images/export',
+ { ids },
+ {
+ responseType: 'blob'
+ }
+ );
+ return response.data;
+ }
+
+ async import(source: File | string, repo?: string, tag?: string) {
+ const formData = new FormData();
+ if (source instanceof File) {
+ formData.append('file', source);
+ } else {
+ formData.append('url', source);
+ }
+ if (repo) formData.append('repo', repo);
+ if (tag) formData.append('tag', tag);
+
+ return this.handleResponse(
+ this.api.post('/images/import', formData, {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ })
+ );
+ }
+
+ async commit(
+ containerId: string,
+ options?: {
+ repo?: string;
+ tag?: string;
+ comment?: string;
+ author?: string;
+ pause?: boolean;
+ changes?: string[];
+ }
+ ) {
+ return this.handleResponse(
+ this.api.post('/images/commit', {
+ containerId,
+ ...options
+ })
+ );
+ }
+
+ async checkMaturity(imageId: string) {
+ return this.handleResponse(this.api.get(`/images/maturity/${imageId}`));
+ }
+
+ async checkMaturityBatch(imageIds: string[]) {
+ if (!imageIds || imageIds.length === 0) {
+ throw new Error('No image IDs provided for batch check');
+ }
+
+ const firstId = imageIds[0];
+ return this.handleResponse(this.api.post(`/images/${firstId}/maturity`, { imageIds }));
+ }
+
+ async updateMaturity(imageId: string, maturityData: any) {
+ return this.handleResponse(this.api.put(`/images/maturity/${imageId}`, maturityData));
+ }
+
+ async getVulnerabilities(imageId: string) {
+ return this.handleResponse(this.api.get(`/images/${imageId}/vulnerabilities`));
+ }
+
+ async scanImage(imageId: string) {
+ return this.handleResponse(this.api.post(`/images/${imageId}/scan`));
+ }
}
diff --git a/frontend/src/routes/images/+page.svelte b/frontend/src/routes/images/+page.svelte
index 1fde92d96..5b63c2027 100644
--- a/frontend/src/routes/images/+page.svelte
+++ b/frontend/src/routes/images/+page.svelte
@@ -37,8 +37,6 @@
let isPullDialogOpen = $state(false);
let isConfirmPruneDialogOpen = $state(false);
- const totalSize = $derived(images?.reduce((acc, img) => acc + (img.Size || 0), 0) || 0);
-
async function loadImages() {
try {
isLoadingImages = true;
@@ -180,7 +178,7 @@
/>
<StatCard
title="Total Size"
- value={formatBytes(totalSize)}
+ value={formatBytes(data.totalSize)}
icon={Package}
iconColor="text-amber-500"
class="border-l-4 border-l-amber-500"
diff --git a/frontend/src/routes/images/+page.ts b/frontend/src/routes/images/+page.ts
index 82534575b..171443896 100644
--- a/frontend/src/routes/images/+page.ts
+++ b/frontend/src/routes/images/+page.ts
@@ -15,6 +15,7 @@ export const load: PageLoad = async () => {
};
const dockerInfo = await systemAPI.getDockerInfo();
+ const totalSize = await environmentAPI.getTotalImageSize();
const images = await environmentAPI.getImages(
imageRequestOptions.pagination,
@@ -23,5 +24,5 @@ export const load: PageLoad = async () => {
imageRequestOptions.filters
);
- return { dockerInfo, images, imageRequestOptions };
+ return { dockerInfo, totalSize, images, imageRequestOptions };
};