Skip to content

Commit

Permalink
Use the Location header if it available
Browse files Browse the repository at this point in the history
Faust service PR  grame-cncm/faustservice#10 implements a
scheme whereby the location of a generated artifact is returned in the Location header.

This allows us, in the IDE, to be independent of the artifact naming implemented by
the faust service. This PR exploits that feature, while still retaining the hard-coded
`binary.zip` artifact name for when the Location header is not present.
  • Loading branch information
Martin Bartlett authored and sletz committed Jul 6, 2024
1 parent 9e5d3d6 commit d34fe0c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,11 @@ $(async () => {
$.ajax({
method: "GET",
url: `${path}/precompile`
}).done((result) => {
}).done((result, status, jqXHR) => {
if (result === "DONE") {
const href = `${path}/${plat === "android" ? "binary.apk" : "binary.zip"}`;
// faustservice MAY return Location : https://github.com/grame-cncm/faustservice/pull/10
const location = jqXHR.getResponseHeader("Location")
const href = location ? `${server}/${location}` : `${path}/${plat === "android" ? "binary.apk" : "binary.zip"}`;
$("#a-export-download").attr({ href });
$("#export-download").show();
if (download === true) {
Expand All @@ -934,7 +936,7 @@ $(async () => {
$("#qr-code").show();
QRCode.toCanvas(
$<HTMLCanvasElement>("#qr-code")[0],
`${path}/${plat === "android" ? "binary.apk" : "binary.zip"}`
href
);
return;
}
Expand Down Expand Up @@ -1542,9 +1544,11 @@ $(async () => {
$.ajax({
method: "GET",
url: `${path}/precompile`
}).done((result) => {
}).done((result, status, jqXHR) => {
if (result === "DONE") {
const href = `${path}/binary.zip`;
// faustservice MAY return Location : https://github.com/grame-cncm/faustservice/pull/10
const location = jqXHR.getResponseHeader("Location")
const href = location ? `${server}/${location}` : `${path}/binary.zip`;
((e.originalEvent as MessageEvent).source as WindowProxy).postMessage({ type: "exported", href }, "*");
}
}).fail((jqXHR, textStatus) => {
Expand Down

0 comments on commit d34fe0c

Please sign in to comment.