-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,5 @@ next-env.d.ts | |
**/public/fallback** | ||
**/public/precache** | ||
|
||
#Cloudflare | ||
# Cloudflare | ||
.wrangler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const corsHeaders = { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS,DELETE", | ||
"Access-Control-Allow-Headers": "Content-Type", | ||
"Access-Control-Max-Age": "86400", | ||
"Content-Type": "application/json;charset=utf-8", | ||
}; | ||
|
||
export const onRequestGet: PagesFunction = async (context) => { | ||
let apiUrl = | ||
"https://api.github.com/repos/portapack-mayhem/mayhem-firmware/releases/latest"; | ||
|
||
let apiResponse = await fetch(apiUrl, { | ||
method: "GET", | ||
headers: { "User-Agent": "portapack-mayhem" }, | ||
}); | ||
|
||
if (!apiResponse.ok) { | ||
throw new Error(`HTTP error! status: ${apiResponse.status}`); | ||
} | ||
|
||
let apiData: any = await apiResponse.json(); | ||
// assuming you want to fetch the first release data | ||
let browser_download_url = apiData.assets.find((asset: any) => { | ||
const assetName: string = asset["name"]; | ||
return assetName.includes(".ppfw.tar"); | ||
}).browser_download_url; | ||
console.log(browser_download_url); | ||
|
||
let fileUrl = browser_download_url; | ||
|
||
let response = await fetch(fileUrl, context.request); | ||
|
||
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( | ||
"Content-Disposition", | ||
`attachment; filename="${fileName}"` | ||
); | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters