-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from RationAI/dev/js-server
feat: more stable js server behavior
- Loading branch information
Showing
5 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
module.exports.safeScanDir = function (directory) { | ||
let resolvedPaths = []; | ||
try { | ||
const entries = fs.readdirSync(directory); | ||
|
||
resolvedPaths = entries.map((entry) => { | ||
const fullPath = path.join(directory, entry); | ||
try { | ||
const realPath = fs.realpathSync(fullPath); | ||
fs.statSync(realPath); | ||
return entry; | ||
} catch (err) { | ||
console.error(`Failed to resolve or stat: ${fullPath}`, err.message); | ||
return null; | ||
} | ||
}); | ||
} catch (err) { | ||
console.error(`Error scanning directory: ${directory}`, err.message); | ||
} | ||
return resolvedPaths.filter(Boolean); | ||
} |