Skip to content

Commit

Permalink
fix : refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
qfdk committed Feb 22, 2024
1 parent a6dc761 commit eb3436a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const bodyParser = require('body-parser');
const app = express();
const session = require('express-session');

const { checkUser } = require('./middlewares/security');
const {checkUser} = require('./middlewares/security');

const io = require('socket.io')();
const favicon = require('serve-favicon');
Expand Down Expand Up @@ -35,7 +35,7 @@ app.use(session({
app.use('/static', express.static(__dirname + '/public'));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));

app.all('*', (req, res, next) => {
Expand All @@ -44,7 +44,7 @@ app.all('*', (req, res, next) => {
'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res.header('Access-Control-Allow-Methods',
'PUT, POST, GET, DELETE, OPTIONS');
if (req.method == 'OPTIONS') {
if (req.method === 'OPTIONS') {
res.send(200); /* speedup options */
} else {
next();
Expand Down
2 changes: 1 addition & 1 deletion middlewares/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ const checkUser = (req, res, next) => {
};

module.exports = {
checkUser,
checkUser
};
12 changes: 7 additions & 5 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ router.get('/images/remove/:id', (req, res, next) => {
});
});

router.get('/search/:name', (req, res, next) => {
router.get('/search/:name', async (req, res, next) => {
const name = req.params.name;
docker.searchImages({term: name}, (err, data) => {
if (err) throw err;
res.json(data);
});
try {
const data = await docker.searchImages({term: name});
return res.json(data);
} catch (e) {
return res.json(e);
}
});

module.exports = router;
20 changes: 10 additions & 10 deletions routes/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const returnContainersRouter = (io) => {
res.render('containers',
{
containers: containers,
images: listImages,
images: listImages
});
});
});
Expand Down Expand Up @@ -54,15 +54,15 @@ const returnContainersRouter = (io) => {
AttachStderr: true,
Tty: false,
HostConfig: {
PortBindings: {},
},
PortBindings: {}
}
};

// name
if (req.body.containerName !== '') {
options = {
...options,
name: req.body.containerName,
name: req.body.containerName
};
}

Expand All @@ -76,8 +76,8 @@ const returnContainersRouter = (io) => {
'Binds': [src + ':' + dis],
'RestartPolicy': {
'Name': req.body.isAlways === 'on' ? 'always' : '',
'MaximumRetryCount': 5,
},
'MaximumRetryCount': 5
}
};
}

Expand Down Expand Up @@ -111,7 +111,7 @@ const returnContainersRouter = (io) => {
//Cmd: ['/bin/sh'],
OpenStdin: false,
StdinOnce: false,
...options,
...options
};
docker.createContainer(runOpt).then(function (container) {
return container.start();
Expand All @@ -138,7 +138,7 @@ const returnContainersRouter = (io) => {
'AttachStderr': true,
'AttachStdin': true,
'Tty': true,
Cmd: ['/bin/bash'],
Cmd: ['/bin/bash']
};
socket.on('resize', (data) => {
container.resize({h: data.rows, w: data.cols}, () => {
Expand All @@ -152,7 +152,7 @@ const returnContainersRouter = (io) => {
stdout: true,
stderr: true,
// fix vim
hijack: true,
hijack: true
};

container.wait((err, data) => {
Expand Down Expand Up @@ -188,7 +188,7 @@ const returnContainersRouter = (io) => {
follow: true,
stdout: true,
stderr: true,
timestamps: false,
timestamps: false
};

const handler = (err, stream) => {
Expand Down
6 changes: 2 additions & 4 deletions routes/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ const returnImagesRouter = (io) => {
// imageSize
res.locals.imageSize = (str) => {
const newSiez = parseInt(str, 10);
str = (newSiez / 1000 / 1000).toFixed(2).
toString().
substring(0, 4);
str = (newSiez / 1000 / 1000).toFixed(2).toString().substring(0, 4);
if (str.indexOf('.') == 3) {
return str.split('.')[0];
}
return str;
};
res.render('images', {
images: listImages,
images: listImages
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion routes/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const returnOverviewRouter = (io) => {
// console.log(info)
if (err) {
res.render('error', {
message: "Docker is running ?",
message: 'Docker is running ?',
error: err
});
} else {
Expand Down

0 comments on commit eb3436a

Please sign in to comment.