mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
✨ Add "Add to homarr" feature and move code
This commit is contained in:
@@ -8,7 +8,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { id } = req.query as { id: string };
|
||||
const { action } = req.query;
|
||||
// Get the action on the request (start, stop, restart)
|
||||
if (action !== 'start' && action !== 'stop' && action !== 'restart') {
|
||||
if (action !== 'start' && action !== 'stop' && action !== 'restart' && action !== 'remove') {
|
||||
return res.status(400).json({
|
||||
statusCode: 400,
|
||||
message: 'Invalid action',
|
||||
@@ -29,39 +29,25 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
switch (action) {
|
||||
case 'start':
|
||||
container.start((err, data) => {
|
||||
if (err) {
|
||||
res.status(500).json({
|
||||
message: err,
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'stop':
|
||||
container.stop((err, data) => {
|
||||
if (err) {
|
||||
res.status(500).json({
|
||||
message: err,
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'restart':
|
||||
container.restart((err, data) => {
|
||||
if (err) {
|
||||
res.status(500).json({
|
||||
message: err,
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(400).json({
|
||||
message: 'Invalid action',
|
||||
});
|
||||
try {
|
||||
switch (action) {
|
||||
case 'remove':
|
||||
await container.remove();
|
||||
break;
|
||||
case 'start':
|
||||
container.start();
|
||||
break;
|
||||
case 'stop':
|
||||
container.stop();
|
||||
break;
|
||||
case 'restart':
|
||||
container.restart();
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
message: err,
|
||||
});
|
||||
}
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -5,12 +5,8 @@ import Docker from 'dockerode';
|
||||
const docker = new Docker();
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
docker.listContainers({ all: true }, (err, containers) => {
|
||||
if (err) {
|
||||
res.status(500).json({ error: err });
|
||||
}
|
||||
return res.status(200).json(containers);
|
||||
});
|
||||
const containers = await docker.listContainers({ all: true });
|
||||
return res.status(200).json(containers);
|
||||
}
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
Reference in New Issue
Block a user