Add netlify-git backend

This commit is contained in:
Mathias Biilmann Christensen
2016-09-04 19:55:14 +02:00
parent e04b1e80c5
commit 2980ba8565
6 changed files with 424 additions and 7 deletions

View File

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