Skip to content

Instantly share code, notes, and snippets.

@ramsaylanier
Created January 14, 2019 18:03
Show Gist options
  • Save ramsaylanier/fbe19a28382c3bcc77f4911573d6e4a1 to your computer and use it in GitHub Desktop.
Save ramsaylanier/fbe19a28382c3bcc77f4911573d6e4a1 to your computer and use it in GitHub Desktop.
Module Docs fileController handlers
// 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