Skip to content

Commit

Permalink
Merge pull request #30 from portapack-mayhem/file_browser
Browse files Browse the repository at this point in the history
File browser
  • Loading branch information
jLynx authored Jan 14, 2024
2 parents c6e32cf + 3dc76b9 commit 0f1552a
Show file tree
Hide file tree
Showing 13 changed files with 916 additions and 396 deletions.
44 changes: 22 additions & 22 deletions functions/api/fetch_nightly_firmware.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS,DELETE",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,OPTIONS,DELETE",
"Access-Control-Allow-Headers": "*",
"Access-Control-Max-Age": "86400",
}
};

export const onRequestGet: PagesFunction = async (context) => {
let apiUrl =
"https://api.github.com/repos/portapack-mayhem/mayhem-firmware/releases"
"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}`)
throw new Error(`HTTP error! status: ${apiResponse.status}`);
}

let apiData: any = await apiResponse.json()
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)
const assetName: string = asset["name"];
return assetName.includes(".ppfw.tar");
}).browser_download_url;
console.log(browser_download_url);

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

if (!resourceResponse.ok) {
throw new Error(`HTTP error! status: ${resourceResponse.status}`)
throw new Error(`HTTP error! status: ${resourceResponse.status}`);
}

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

let proxyResponse = new Response(resourceBody, resourceResponse)
let proxyResponse = new Response(resourceBody, resourceResponse);
Object.entries(corsHeaders).forEach(([key, value]) => {
proxyResponse.headers.set(key, value)
})
proxyResponse.headers.set(key, value);
});
proxyResponse.headers.set(
"Content-Disposition",
`attachment; filename="${fileName}`
)
);

return proxyResponse
}
return proxyResponse;
};
4 changes: 2 additions & 2 deletions functions/api/fetch_stable_firmware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS,DELETE",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,OPTIONS,DELETE",
"Access-Control-Allow-Headers": "*",
"Access-Control-Max-Age": "86400",
};

Expand Down
52 changes: 49 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "^10.0.2",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@types/w3c-web-serial": "^1.0.6",
"eslint-plugin-tailwindcss": "^3.13.1",
"install": "^0.13.0",
Expand Down
Loading

0 comments on commit 0f1552a

Please sign in to comment.