Fixes filter files by extension

This commit is contained in:
Joseph Earl
2017-04-14 19:19:45 +01:00
parent 2047fda27c
commit 265146e2d1
9 changed files with 141 additions and 7 deletions

@ -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) {

@ -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);
}