mirror of
https://github.com/CyberL1/dlinux-dashboard.git
synced 2025-01-22 01:19:18 -05:00
feat: container state management
This commit is contained in:
parent
77ce186675
commit
e2e4b75681
29
src/routes/containers/_id/index.ts
Normal file
29
src/routes/containers/_id/index.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import type {
|
||||||
|
Container,
|
||||||
|
RemoveContainerParams,
|
||||||
|
RemoveContainerQuery,
|
||||||
|
} from "#src/types/Container.ts";
|
||||||
|
import { getContainer } from "#src/utils/containers.ts";
|
||||||
|
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||||
|
|
||||||
|
export default (fastify: FastifyInstance) => {
|
||||||
|
fastify.get("/", (req: FastifyRequest<{ Params: Container }>) => {
|
||||||
|
const container = getContainer(req.params.id);
|
||||||
|
return container.inspect();
|
||||||
|
});
|
||||||
|
|
||||||
|
fastify.delete(
|
||||||
|
"/",
|
||||||
|
async (
|
||||||
|
req: FastifyRequest<{
|
||||||
|
Params: RemoveContainerParams;
|
||||||
|
Querystring: RemoveContainerQuery;
|
||||||
|
}>,
|
||||||
|
) => {
|
||||||
|
const container = getContainer(req.params.id);
|
||||||
|
|
||||||
|
await container.remove({ force: req.query.force === "true" });
|
||||||
|
return container;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
12
src/routes/containers/_id/restart.ts
Normal file
12
src/routes/containers/_id/restart.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import type { Container } from "#src/types/Container.ts";
|
||||||
|
import { getContainer } from "#src/utils/containers.ts";
|
||||||
|
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||||
|
|
||||||
|
export default (fastify: FastifyInstance) => {
|
||||||
|
fastify.put("/", async (req: FastifyRequest<{ Params: Container }>) => {
|
||||||
|
const container = getContainer(req.params.id);
|
||||||
|
|
||||||
|
await container.restart();
|
||||||
|
return container.inspect();
|
||||||
|
});
|
||||||
|
};
|
12
src/routes/containers/_id/start.ts
Normal file
12
src/routes/containers/_id/start.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import type { Container } from "#src/types/Container.ts";
|
||||||
|
import { getContainer } from "#src/utils/containers.ts";
|
||||||
|
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||||
|
|
||||||
|
export default (fastify: FastifyInstance) => {
|
||||||
|
fastify.put("/", async (req: FastifyRequest<{ Params: Container }>) => {
|
||||||
|
const container = getContainer(req.params.id);
|
||||||
|
|
||||||
|
await container.start();
|
||||||
|
return container.inspect();
|
||||||
|
});
|
||||||
|
};
|
@ -3,8 +3,10 @@ import { getContainer } from "#src/utils/containers.ts";
|
|||||||
import type { FastifyInstance, FastifyRequest } from "fastify";
|
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||||
|
|
||||||
export default (fastify: FastifyInstance) => {
|
export default (fastify: FastifyInstance) => {
|
||||||
fastify.get("/", (req: FastifyRequest<{ Params: Container }>) => {
|
fastify.put("/", async (req: FastifyRequest<{ Params: Container }>) => {
|
||||||
const container = getContainer(req.params.id);
|
const container = getContainer(req.params.id);
|
||||||
|
|
||||||
|
await container.stop();
|
||||||
return container.inspect();
|
return container.inspect();
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -7,3 +7,11 @@ export interface Container {
|
|||||||
export interface CreateContainerBody {
|
export interface CreateContainerBody {
|
||||||
image: string;
|
image: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RemoveContainerParams {
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RemoveContainerQuery {
|
||||||
|
force: string;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user