mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: cloudcmd: putout v34.0.7
This commit is contained in:
parent
552d95013b
commit
afdf74342a
2 changed files with 16 additions and 17 deletions
|
|
@ -128,7 +128,7 @@
|
|||
"package-json": "^8.1.0",
|
||||
"ponse": "^7.0.0",
|
||||
"pullout": "^4.0.0",
|
||||
"putout": "^33.13.3",
|
||||
"putout": "^34.0.7",
|
||||
"redzip": "^3.0.0",
|
||||
"rendy": "^4.1.3",
|
||||
"restafary": "^11.0.0",
|
||||
|
|
|
|||
|
|
@ -22,56 +22,56 @@ const DEFAULT_MENU_PATH = join(__dirname, '../static/user-menu.js');
|
|||
module.exports = currify(async ({menuName}, req, res, next) => {
|
||||
if (req.url.indexOf(URL))
|
||||
return next();
|
||||
|
||||
|
||||
const {method} = req;
|
||||
|
||||
|
||||
if (method === 'GET')
|
||||
return await onGET({
|
||||
req,
|
||||
res,
|
||||
menuName,
|
||||
});
|
||||
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
async function onGET({req, res, menuName}) {
|
||||
const {dir} = req.query;
|
||||
const url = req.url.replace(URL, '');
|
||||
|
||||
|
||||
if (url === '/default')
|
||||
return sendDefaultMenu(res);
|
||||
|
||||
|
||||
const {findUp} = await import('find-up');
|
||||
|
||||
|
||||
const [errorFind, currentMenuPath] = await tryToCatch(findUp, [menuName], {
|
||||
cwd: dir,
|
||||
});
|
||||
|
||||
|
||||
if (errorFind && errorFind.code !== 'ENOENT')
|
||||
return res
|
||||
.status(404)
|
||||
.send(errorFind.message);
|
||||
|
||||
|
||||
const homeMenuPath = join(homedir(), menuName);
|
||||
const menuPath = currentMenuPath || homeMenuPath;
|
||||
const [e, source] = await tryToCatch(readFile, menuPath, 'utf8');
|
||||
|
||||
|
||||
if (e && e.code !== 'ENOENT')
|
||||
return res
|
||||
.status(404)
|
||||
.send(e.message);
|
||||
|
||||
|
||||
if (e)
|
||||
return sendDefaultMenu(res);
|
||||
|
||||
|
||||
const [parseError, result] = await transpile(source);
|
||||
|
||||
|
||||
if (parseError)
|
||||
return res
|
||||
.type('js')
|
||||
.send(getError(parseError, source));
|
||||
|
||||
|
||||
res
|
||||
.type('js')
|
||||
.send(result.code);
|
||||
|
|
@ -84,9 +84,9 @@ function getError(error, source) {
|
|||
source,
|
||||
highlightCode: false,
|
||||
})}</pre>\`);
|
||||
|
||||
|
||||
e.code = 'frame';
|
||||
|
||||
|
||||
throw e;
|
||||
`;
|
||||
}
|
||||
|
|
@ -104,7 +104,6 @@ async function transpile(source) {
|
|||
},
|
||||
plugins: [
|
||||
'nodejs',
|
||||
'strict-mode',
|
||||
'cloudcmd',
|
||||
],
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue