From 77ce186675a07f38733d4d63d001cf02a0d36d3c Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Tue, 7 Jan 2025 10:56:05 +0100 Subject: [PATCH] refactor: change `inspect` functtions to `get` functions --- src/routes/containers/_id.ts | 5 +++-- src/routes/images/_name.ts | 7 ++++--- src/utils/containers.ts | 4 ++-- src/utils/images.ts | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/routes/containers/_id.ts b/src/routes/containers/_id.ts index b721f83..ec1e10e 100644 --- a/src/routes/containers/_id.ts +++ b/src/routes/containers/_id.ts @@ -1,9 +1,10 @@ import type { Container } from "#src/types/Container.ts"; -import { inspectContainer } from "#src/utils/containers.ts"; +import { getContainer } from "#src/utils/containers.ts"; import type { FastifyInstance, FastifyRequest } from "fastify"; export default (fastify: FastifyInstance) => { fastify.get("/", (req: FastifyRequest<{ Params: Container }>) => { - return inspectContainer(req.params.id); + const container = getContainer(req.params.id); + return container.inspect(); }); }; diff --git a/src/routes/images/_name.ts b/src/routes/images/_name.ts index b42a6ea..4c35289 100644 --- a/src/routes/images/_name.ts +++ b/src/routes/images/_name.ts @@ -1,9 +1,10 @@ -import type { Image } from "#src/types.ts"; -import { inspectImage } from "#src/utils/images.ts"; +import type { Image } from "#src/types/Image.ts"; +import { getImage } from "#src/utils/images.ts"; import type { FastifyInstance, FastifyRequest } from "fastify"; export default (fastify: FastifyInstance) => { fastify.get("/", (req: FastifyRequest<{ Params: Image }>) => { - return inspectImage(req.params.name); + const image = getImage(req.params.name); + return image.inspect(); }); }; diff --git a/src/utils/containers.ts b/src/utils/containers.ts index b467598..f566884 100644 --- a/src/utils/containers.ts +++ b/src/utils/containers.ts @@ -12,9 +12,9 @@ export const getContainers = () => { return containers; }; -export const inspectContainer = (id: string) => { +export const getContainer = (id: string) => { const container = dockerode.getContainer(id); - return container.inspect(); + return container; }; export const createContainer = ({ image }: CreateContainerBody) => { diff --git a/src/utils/images.ts b/src/utils/images.ts index e0a3d15..7156784 100644 --- a/src/utils/images.ts +++ b/src/utils/images.ts @@ -10,7 +10,7 @@ export const getImages = () => { return images; }; -export const inspectImage = async (name: string) => { +export const getImage = (name: string) => { const image = dockerode.getImage(`code-containers/${name}`); - return image.inspect(); + return image; };