diff --git a/.gitignore b/.gitignore
index 8257caf..926e915 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,5 +42,5 @@ next-env.d.ts
**/public/fallback**
**/public/precache**
-#Cloudflare
+# Cloudflare
.wrangler
\ No newline at end of file
diff --git a/functions/api/fetch_firmware.ts b/functions/api/fetch_nightly_firmware.ts
similarity index 50%
rename from functions/api/fetch_firmware.ts
rename to functions/api/fetch_nightly_firmware.ts
index dfe5c9b..a9386c4 100644
--- a/functions/api/fetch_firmware.ts
+++ b/functions/api/fetch_nightly_firmware.ts
@@ -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);
diff --git a/functions/api/fetch_stable_firmware.ts b/functions/api/fetch_stable_firmware.ts
new file mode 100644
index 0000000..19ecdf1
--- /dev/null
+++ b/functions/api/fetch_stable_firmware.ts
@@ -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;
+};
diff --git a/src/app/components/Controller/Controller.tsx b/src/app/components/Controller/Controller.tsx
index 1d9d59d..37fbc58 100644
--- a/src/app/components/Controller/Controller.tsx
+++ b/src/app/components/Controller/Controller.tsx
@@ -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(
@@ -459,7 +459,7 @@ const Controller = () => {
>
Test
*/}
- {/* */}
+
{/* */}