Created
January 14, 2019 18:03
-
-
Save ramsaylanier/fbe19a28382c3bcc77f4911573d6e4a1 to your computer and use it in GitHub Desktop.
Module Docs fileController handlers
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
// gets directory names from a path, excluding blacklisted names. Returns an array of strings. | |
exports.getFiles = (path, config) => async (req, res) => { | |
const files = await readdir(path) | |
const filteredFiles = filterThroughBlacklist(files) | |
res.send({ files: filteredFiles, config }) | |
} | |
// Gets README content for package and all first-level children. | |
exports.getPackage = path => async (req, res) => { | |
const name = req.params.name | |
const dir = `${path}/${name}` | |
try { | |
const { files, readmeContent, packageInfo } = await getDirectoryContent(dir) | |
const children = await pipe( | |
getDirectories, | |
getPackagesFromChildren(dir) | |
)(files) | |
const pkg = { | |
path: dir, | |
content: readmeContent, | |
info: packageInfo, | |
children: children | |
} | |
res.send({ pkg }) | |
} catch (err) { | |
console.log("Unable to scan directory: " + err) | |
res.send({ pkg: "No Readme Found" }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment