better code
Massimo Melina committed
May 7, 2023 at 20:14 UTC
5847633a714de977e353ef7e1e44236129a47705
1 file changed
+4
-4
src/api.vfs.ts
+4
-4
@@ -16,7 +16,7 @@ import _ from 'lodash'
16
import { stat } from 'fs/promises'
17
import { ApiError, ApiHandlers } from './apiMiddleware'
18
import { dirname, extname, join, resolve } from 'path'
19
-import { dirStream, isWindowsDrive, makeMatcher } from './misc'
19
+import { dirStream, isDirectory, isWindowsDrive, makeMatcher } from './misc'
20
import {
21
IS_WINDOWS,
22
HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR, HTTP_CONFLICT, HTTP_NOT_ACCEPTABLE,
@@ -71,8 +71,8 @@ const apis: ApiHandlers = {
71
|| undefined,
72
name: node === vfs ? undefined : getNodeName(node),
73
type: isDir ? 'folder' : undefined,
74
- children: node.children && await Promise.all(node.children.map(async original =>
75
- recur(applyParentToChild(original, node)) ))
74
+ children: node.children && await Promise.all(node.children.map(child =>
75
+ recur(applyParentToChild(child, node)) ))
76
}
77
}
78
},
@@ -175,7 +175,7 @@ const apis: ApiHandlers = {
175
async resolve_path({ path, closestFolder }) {
176
path = resolve(path)
177
if (closestFolder)
178
- while (path && !await stat(path).then(x => x.isDirectory(), () => 0))
178
+ while (path && !await isDirectory(path))
179
path = dirname(path)
180
return { path }
181
},