Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading firmware file from Github #25

Closed
jLynx opened this issue Jan 11, 2024 · 1 comment
Closed

Downloading firmware file from Github #25

jLynx opened this issue Jan 11, 2024 · 1 comment

Comments

@jLynx
Copy link
Contributor

jLynx commented Jan 11, 2024

Since we cannot download the file directly from GitHub because of the CORS issue, we will need to create a Cloudflare function that acts as a proxy for us to download the file. But we need to limit its scope so that it can only download from this specific repo.

Here is some example code to get started (Note this is for a worker, so will need to be updated to a function)

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url)

  // Define the URL for the file to be downloaded
  let fileUrl = 'https://example.com/file.zip' 

  // Modify this for the logic to determine your file URL
  // if(url.pathname.startsWith('/specific-path/')) 
  //    fileUrl = 'https://example.com/file2.zip'

  let response = await fetch(fileUrl, request)

  // 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="yourdesiredfilename.zip"`)

  return response
}
@jLynx
Copy link
Contributor Author

jLynx commented Jan 11, 2024

Done

@jLynx jLynx closed this as completed Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant