Merge pull request #902 from dannywritescode/dev

Fix: Loading samples with special characters in the file name
This commit is contained in:
Yotam Mann 2021-10-13 13:26:38 -04:00 committed by GitHub
commit f08b317f9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -372,7 +372,13 @@ export class ToneAudioBuffer extends Tone {
// make sure there is a slash between the baseUrl and the url
const baseUrl = ToneAudioBuffer.baseUrl === "" || ToneAudioBuffer.baseUrl.endsWith("/") ? ToneAudioBuffer.baseUrl : ToneAudioBuffer.baseUrl + "/";
const response = await fetch(baseUrl + url);
// encode special characters in file path
const location = document.createElement("a");
location.href = (baseUrl + url);
location.pathname = (location.pathname + location.hash).split("/").map(encodeURIComponent).join("/");
const response = await fetch(location.href);
if (!response.ok) {
throw new Error(`could not load url: ${url}`);
}