Merge pull request #240 from tidalcycles/load-samples-from-url

feat: support github: links
This commit is contained in:
Felix Roos 2022-11-02 23:16:43 +01:00 committed by GitHub
commit 06d6621c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -104,10 +104,18 @@ export const loadGithubSamples = async (path, nameFn) => {
export const samples = async (sampleMap, baseUrl = sampleMap._base || '') => {
if (typeof sampleMap === 'string') {
if (sampleMap.startsWith('github:')) {
const [_, path] = sampleMap.split('github:');
sampleMap = `https://raw.githubusercontent.com/${path}/strudel.json`;
}
const base = sampleMap.split('/').slice(0, -1).join('/');
return fetch(sampleMap)
.then((res) => res.json())
.then((json) => samples(json, baseUrl || json._base || base));
.then((json) => samples(json, baseUrl || json._base || base))
.catch((error) => {
console.error(error);
throw new Error(`error loading "${sampleMap}"`);
});
}
sampleCache.current = {
...sampleCache.current,