mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: limit 2 level to only 5 children
This commit is contained in:
1 parent
34d5ace664
commit
f43fa1b5ef
3 files changed
+24
-22
No files matched your search
@@ -19,7 +19,6 @@ const commandListeners = {
|
||||
|
||||
async function handleCommand(command) {
|
||||
const argv = minimist(command.split(' '))
|
||||
console.log(argv)
|
||||
const name = argv._[0]
|
||||
const listeners = commandListeners[name]
|
||||
if (!listeners) return {}
|
||||
|
||||
@@ -5,30 +5,35 @@ async function collectFilesInfo(inputPath, level = 0) {
|
||||
const stats = await fs.stat(inputPath)
|
||||
const discovered = level === 0
|
||||
const name = path.basename(inputPath)
|
||||
const file = {
|
||||
path: inputPath,
|
||||
name,
|
||||
type: stats.isDirectory() ? 'folder' : 'file',
|
||||
discovered,
|
||||
}
|
||||
if (stats.isFile()) {
|
||||
return [file]
|
||||
}
|
||||
if (stats.isDirectory()) {
|
||||
const entries = await fs.readdir(inputPath)
|
||||
const result = await Promise.all(
|
||||
entries.map((entry) =>
|
||||
collectFilesInfo(path.join(inputPath, entry), level + 1)
|
||||
const files = [
|
||||
{
|
||||
path: inputPath,
|
||||
name,
|
||||
type: stats.isDirectory() ? 'folder' : 'file',
|
||||
discovered,
|
||||
},
|
||||
]
|
||||
if (stats.isDirectory() && level < 2) {
|
||||
try {
|
||||
let entries = await fs.readdir(inputPath)
|
||||
if (level > 0) {
|
||||
entries = entries.slice(0, 5)
|
||||
}
|
||||
const result = await Promise.all(
|
||||
entries.map((entry) =>
|
||||
collectFilesInfo(path.join(inputPath, entry), level + 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
return [file, ...result.flat()]
|
||||
files.push(...result.flat())
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return []
|
||||
return files
|
||||
}
|
||||
|
||||
async function discoverFiles(argv) {
|
||||
const targetPath = argv._.length < 2 ? ['.'] : argv._.slice(1)
|
||||
console.log(targetPath)
|
||||
const result = await Promise.all(
|
||||
targetPath.map((p) => path.resolve(process.cwd(), p)).map(collectFilesInfo)
|
||||
)
|
||||
|
||||
@@ -29,8 +29,6 @@ precmd() {
|
||||
export CMD_ERROR_FILE=/tmp/cmd.error
|
||||
|
||||
# Now run your Node.js script with the result as an argument
|
||||
node /usr/local/lib/container/cli.js
|
||||
|
||||
rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null # cleanup
|
||||
node /usr/local/lib/container/cli.js; rm /tmp/cmd.out /tmp/cmd.error 2>/dev/null
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user