From a6dc761acec2f54117af3002b6fe6d2999b51f9a Mon Sep 17 00:00:00 2001 From: qfdk Date: Thu, 22 Feb 2024 13:25:14 +0100 Subject: [PATCH] fix : async function --- package.json | 2 +- routes/api.js | 81 +++++++++++++++++++-------------------- views/terminal.html.old | 5 --- yarn.lock | 85 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 121 insertions(+), 52 deletions(-) delete mode 100644 views/terminal.html.old diff --git a/package.json b/package.json index 75f2364..995f58e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "body-parser": "1.20.1", "dockerode": "^4.0.2", - "ejs": "^2.5.7", + "ejs": "3.1.7", "express": "^4.16.4", "express-session": "^1.17.1", "express-status-monitor": "^1.2.8", diff --git a/routes/api.js b/routes/api.js index 52f0838..14133d0 100644 --- a/routes/api.js +++ b/routes/api.js @@ -21,7 +21,7 @@ router.get('/overview', async (req, res, next) => { */ router.get('/containers', async (req, res, next) => { try { - const listContainers = await docker.listContainers({ all: true }); + const listContainers = await docker.listContainers({all: true}); return res.json(listContainers); } catch (err) { res.json({ @@ -31,65 +31,62 @@ router.get('/containers', async (req, res, next) => { } }); -router.get('/containers/start/:id', (req, res, next) => { +router.get('/containers/start/:id', async (req, res, next) => { const container = docker.getContainer(req.params.id); - container.start((err, data) => { - if (!err) { - res.json({ - code: 200, - msg: 'OK', - }); - } else { - res.json({ - code: 400, - msg: err.toString(), - }); - } - }); + try { + await container.start(); + res.json({ + code: 200, + msg: 'OK' + }); + } catch (err) { + res.json({ + code: 400, + msg: err.toString() + }); + } }); -router.get('/containers/stop/:id', (req, res, next) => { +router.get('/containers/stop/:id', async (req, res, next) => { const container = docker.getContainer(req.params.id); - container.stop((err, data) => { - if (!err) { - res.json({ - code: 200, - msg: 'OK', - }); - } else { - res.json({ - code: 400, - msg: err.toString(), - }); - } - }); + try { + await container.stop(); + res.json({ + code: 200, + msg: 'OK' + }); + } catch (err) { + res.json({ + code: 400, + msg: err.toString() + }); + } }); router.get('/containers/remove/:id', (req, res, next) => { const container = docker.getContainer(req.params.id); - container.remove({ force: true }, (err, data) => { + container.remove({force: true}, (err, data) => { if (!err) { res.json({ code: 200, - msg: 'OK', + msg: 'OK' }); } else { res.json({ code: 400, - msg: err.toString(), + msg: err.toString() }); } }); }); -router.get('/images', (req, res, next) => { - docker.listImages(null, (err, listImages) => { - if (err) { - res.json(err); - } else { - res.json(listImages); - } - }); +router.get('/images', async (req, res, next) => { + try { + const listImages = await docker.listImages(); + res.json(listImages); + } catch (err) { + res.json(err); + } }); router.get('/images/remove/:id', (req, res, next) => { @@ -98,7 +95,7 @@ router.get('/images/remove/:id', (req, res, next) => { imageId = imageId.split(':')[1]; } const image = docker.getImage(imageId); - image.remove({ force: true }, (err, data) => { + image.remove({force: true}, (err, data) => { if (err) { res.json(err); } else { @@ -109,7 +106,7 @@ router.get('/images/remove/:id', (req, res, next) => { router.get('/search/:name', (req, res, next) => { const name = req.params.name; - docker.searchImages({ term: name }, (err, data) => { + docker.searchImages({term: name}, (err, data) => { if (err) throw err; res.json(data); }); diff --git a/views/terminal.html.old b/views/terminal.html.old deleted file mode 100644 index 1c29507..0000000 --- a/views/terminal.html.old +++ /dev/null @@ -1,5 +0,0 @@ -<% include include/header.html %> -
-
-
-<% include include/footer.html %> diff --git a/yarn.lock b/yarn.lock index 1eca0cb..4842ea7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25,6 +25,13 @@ after@0.8.2: resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f" integrity sha512-QbJ0NTQ/I9DI3uSJA4cbexiwQeRAfjPScqIbSjUDd9TOrcg6pTkdgziesOqxBMBzit8vFCTwrP27t13vFOORRA== +ansi-styles@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937" + integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg== + dependencies: + color-convert "^2.0.1" + anymatch@~3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" @@ -50,6 +57,11 @@ asn1@^0.2.6: dependencies: safer-buffer "~2.1.0" +async@^3.2.3: + version "3.2.5" + resolved "https://registry.yarnpkg.com/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66" + integrity sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg== + axios@0.26.0: version "0.26.0" resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" @@ -152,6 +164,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -185,6 +204,14 @@ call-bind@^1.0.0: function-bind "^1.1.1" get-intrinsic "^1.0.2" +chalk@^4.0.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chokidar@^3.5.2: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" @@ -205,6 +232,18 @@ chownr@^1.1.1: resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg== +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + component-bind@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1" @@ -327,10 +366,12 @@ ee-first@1.1.1: resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== -ejs@^2.5.7: - version "2.7.4" - resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.7.4.tgz#48661287573dcc53e366c7a1ae52c3a120eec9ba" - integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA== +ejs@3.1.7: + version "3.1.7" + resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.7.tgz#c544d9c7f715783dd92f0bddcf73a59e6962d006" + integrity sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw== + dependencies: + jake "^10.8.5" encodeurl@~1.0.2: version "1.0.2" @@ -466,6 +507,13 @@ express@^4.16.4: utils-merge "1.0.1" vary "~1.1.2" +filelist@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/filelist/-/filelist-1.0.4.tgz#f78978a1e944775ff9e62e744424f215e58352b5" + integrity sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q== + dependencies: + minimatch "^5.0.1" + fill-range@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" @@ -561,6 +609,11 @@ has-flag@^3.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" integrity sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw== +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + has-symbols@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.3.tgz#bb7b2c4349251dce87b125f7bdf874aa7c8b39f8" @@ -645,6 +698,16 @@ isarray@2.0.1: resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e" integrity sha512-c2cu3UxbI+b6kR3fy0nRnAhodsvR9dx7U5+znCOzdj6IfP3upFURTr0Xl5BlQZNKZjEtxrmVyfSdeE3O57smoQ== +jake@^10.8.5: + version "10.8.7" + resolved "https://registry.yarnpkg.com/jake/-/jake-10.8.7.tgz#63a32821177940c33f356e0ba44ff9d34e1c7d8f" + integrity sha512-ZDi3aP+fG/LchyBzUM804VjddnwfSfsdeYkwt8NcbKRvo4rFkjhs456iLFn3k2ZUWvNe4i48WACDbza8fhq2+w== + dependencies: + async "^3.2.3" + chalk "^4.0.2" + filelist "^1.0.4" + minimatch "^3.1.2" + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" @@ -691,6 +754,13 @@ minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" +minimatch@^5.0.1: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== + dependencies: + brace-expansion "^2.0.1" + minimist@^1.2.5: version "1.2.6" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" @@ -1071,6 +1141,13 @@ supports-color@^5.5.0: dependencies: has-flag "^3.0.0" +supports-color@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da" + integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw== + dependencies: + has-flag "^4.0.0" + tar-fs@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.0.1.tgz#e44086c1c60d31a4f0cf893b1c4e155dabfae9e2"