Merge pull request #370 from josephearl/filter-files-extension
Fixes #278 Filter folder collection files by extension
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user