Skip to content

Commit

Permalink
Fixed stable API
Browse files Browse the repository at this point in the history
  • Loading branch information
jLynx committed Feb 25, 2024
1 parent b69adfd commit cc3f0b0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions functions/api/fetch_stable_firmware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ export const onRequestGet: PagesFunction = async (context) => {
console.log(browser_download_url);

let fileUrl = browser_download_url;
const resourceResponse = await fetch(fileUrl);

let response = await fetch(fileUrl, context.request);
if (!resourceResponse.ok) {
throw new Error(`HTTP error! status: ${resourceResponse.status}`);
}

const resourceBody = await resourceResponse.body;
let fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);

// You can modify the response here, like setting content-disposition to force a file download
response = new Response(response.body, response);
response.headers.set(
let proxyResponse = new Response(resourceBody, resourceResponse);
Object.entries(corsHeaders).forEach(([key, value]) => {
proxyResponse.headers.set(key, value);
});
proxyResponse.headers.set(
"Content-Disposition",
`attachment; filename="${fileName}"`
`attachment; filename="${fileName}`
);

return response;
return proxyResponse;
};

0 comments on commit cc3f0b0

Please sign in to comment.