Add netlify-git backend
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import semaphore from 'semaphore';
|
||||
import {createEntry} from '../../valueObjects/Entry';
|
||||
import AuthenticationPage from './AuthenticationPage';
|
||||
import API from './API';
|
||||
|
||||
const MAX_CONCURRENT_DOWNLOADS = 10;
|
||||
|
||||
export default class GitHub {
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
@ -29,13 +32,19 @@ export default class GitHub {
|
||||
}
|
||||
|
||||
entries(collection) {
|
||||
return this.api.listFiles(collection.get('folder')).then((files) => (
|
||||
Promise.all(files.map((file) => (
|
||||
this.api.readFile(file.path, file.sha).then((data) => {
|
||||
return createEntry(file.path, file.path.split('/').pop().replace(/\.[^\.]+$/, ''), data);
|
||||
})
|
||||
)))
|
||||
)).then((entries) => ({
|
||||
return this.api.listFiles(collection.get('folder')).then((files) => {
|
||||
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
|
||||
const promises = [];
|
||||
files.map((file) => {
|
||||
sem.take(() => {
|
||||
promises.push(this.api.readFile(file.path, file.sha).then((data) => {
|
||||
sem.leave();
|
||||
return createEntry(file.path, file.path.split('/').pop().replace(/\.[^\.]+$/, ''), data);
|
||||
}));
|
||||
});
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}).then((entries) => ({
|
||||
pagination: {},
|
||||
entries
|
||||
}));
|
||||
|
Reference in New Issue
Block a user