From d7b82edae3d13805b5261e71527304f97e4ad92d Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 2 Nov 2022 23:13:00 +0100 Subject: [PATCH] feat: support github: links --- packages/webaudio/sampler.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/webaudio/sampler.mjs b/packages/webaudio/sampler.mjs index 68561dbe..4edd3e5e 100644 --- a/packages/webaudio/sampler.mjs +++ b/packages/webaudio/sampler.mjs @@ -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,