Merge pull request #370 from josephearl/filter-files-extension

Fixes #278 Filter folder collection files by extension
This commit is contained in:
Benaiah Mischenko
2017-04-18 16:28:05 -07:00
committed by GitHub
9 changed files with 141 additions and 7 deletions

View File

@ -155,7 +155,14 @@ export default class API {
listFiles(path) {
return this.request(`${ this.repoURL }/contents/${ path }`, {
params: { ref: this.branch },
});
})
.then(files => {
if (!Array.isArray(files)) {
throw new Error(`Cannot list files, path ${path} is not a directory but a ${files.type}`);
}
return files;
})
.then(files => files.filter(file => file.type === "file"));
}
readUnpublishedBranchFile(contentKey) {

View File

@ -1,6 +1,7 @@
import semaphore from "semaphore";
import AuthenticationPage from "./AuthenticationPage";
import API from "./API";
import { fileExtension } from '../../lib/pathHelper'
const MAX_CONCURRENT_DOWNLOADS = 10;
@ -39,8 +40,9 @@ export default class GitHub {
return Promise.resolve(this.token);
}
entriesByFolder(collection) {
entriesByFolder(collection, extension) {
return this.api.listFiles(collection.get("folder"))
.then(files => files.filter(fileExtension(file.name) === extension))
.then(this.fetchFiles);
}