Repository navigation
Fix firmware OTA URL to use correct bucket public URL - #11
Merged
Merged
Conversation
- Add R2_FIRMWARE_PUBLIC_URL env var for firmware bucket public URL - Build firmware URLs from R2_FIRMWARE_PUBLIC_URL with fallback to R2_PUBLIC_URL - Add optional publicBaseUrlOverride parameter to uploadToR2 - Log warning when firmware bucket is set but no public URL configured - Update .env.example with R2_FIRMWARE_PUBLIC_URL documentation - Update docs/firmware-ota.md with configuration details - Add comprehensive unit tests for URL selection logic - All 222 tests pass Co-authored-by: James Brown <JamesSmartCell@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Firmware binaries are uploaded to a separate Cloudflare R2 bucket (
R2_FIRMWARE_BUCKET_NAME, e.g.esp-firmware), butsrc/service/CloudflareR2.tsbuilds the returned public URL fromR2_PUBLIC_URLonly, which is the camera bucket's public r2.dev URL. This causes firmware download URLs to point at the wrong bucket, resulting in 404 errors on OTA updates.Solution
This PR adds support for a new environment variable
R2_FIRMWARE_PUBLIC_URLto specify the public URL for the firmware bucket.Changes
Added
R2_FIRMWARE_PUBLIC_URLsupport inCloudflareR2.ts:R2_FIRMWARE_PUBLIC_URLwhen availableR2_PUBLIC_URLif firmware-specific URL is not setr2.cloudflarestorage.comform as a last resortR2_PUBLIC_URL(unchanged behavior)Added startup warning:
R2_FIRMWARE_BUCKET_NAMEis set but neitherR2_FIRMWARE_PUBLIC_URLnorR2_PUBLIC_URLis configuredDocumentation updates:
R2_FIRMWARE_PUBLIC_URLto.env.examplewith inline commentdocs/firmware-ota.mdwith configuration section explaining the new variable and fallback behaviorComprehensive unit tests:
src/__tests__/cloudflare-r2-url.test.tscovering:R2_FIRMWARE_PUBLIC_URLwhen setR2_PUBLIC_URLwhen firmware URL is not setcloudflarestorage.comwhen no public URL is configuredTest Results
All 222 tests pass:
Backward Compatibility
✅ Fully backward compatible. When
R2_FIRMWARE_PUBLIC_URLis not set, the system falls back toR2_PUBLIC_URL, then to the existingr2.cloudflarestorage.comform. Existing deployments will continue to work unchanged.