Skip to content

Commit

Permalink
Added firmware download links
Browse files Browse the repository at this point in the history
  • Loading branch information
jLynx committed Jan 11, 2024
1 parent a45b77f commit 0877180
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ next-env.d.ts
**/public/fallback**
**/public/precache**

#Cloudflare
# Cloudflare
.wrangler
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@ const corsHeaders = {
};

export const onRequestGet: PagesFunction = async (context) => {
let fileUrl =
"https://github.com/portapack-mayhem/mayhem-firmware/releases/download/nightly-tag-2024-01-11/mayhem_nightly_n_240111_OCI.ppfw.tar";
let apiUrl =
"https://api.github.com/repos/portapack-mayhem/mayhem-firmware/releases";

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[0].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);

Expand Down
44 changes: 44 additions & 0 deletions functions/api/fetch_stable_firmware.ts
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;
};
6 changes: 3 additions & 3 deletions src/app/components/Controller/Controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const Controller = () => {

const flashLatestFirmware = async () => {
const fileBlob = await downloadFileFromUrl(
"/mayhem_nightly_n_240111_OCI.ppfw.tar"
"https://hackrf.app/api/fetch_firmware"
);

await uploadFile(
Expand Down Expand Up @@ -459,7 +459,7 @@ const Controller = () => {
>
Test
</button> */}
{/* <button
<button
// onClick={() => downloadFile("PLAYLIST.TXT")}
onClick={() => downloadFile("/APPS/pacman.ppma")}
className="h-12 w-12 self-end justify-self-end rounded bg-blue-400 text-white disabled:opacity-50"
Expand All @@ -472,7 +472,7 @@ const Controller = () => {
className="h-12 w-12 self-end justify-self-end rounded bg-blue-400 text-white disabled:opacity-50"
>
FW
</button> */}
</button>
{/* <input type="file" onChange={onFileChange} /> */}
<input
type="text"
Expand Down

0 comments on commit 0877180

Please sign in to comment.