Repository navigation
Add a live solar conditions PNG badge and builder - #1274
Merged
Merged
Conversation
Serve GET /api/badge/solar.png from the in-process NOAA cache, with themed frames, ham status meters, HF band chips, and a five-minute render cache. The /badges page previews the image and copies QRZ, HTML, Markdown, and BBCode snippets. Co-authored-by: accius <accius@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.
What does this PR do?
Adds a public PNG badge of live solar and HF conditions so a QRZ biography (or any page that allows an image but not a script or iframe) can show OpenHamClock data instead of a third-party HamQSL banner.
GET /api/badge/solar.pngdraws SFI, sunspot number, Kp, A index, X-ray class, a UTC timestamp, and an HF day/night band row. Numbers are color-coded with the usual ham thresholds (SFI poor/fair/good/excellent, Kp quiet/unsettled/storm plus the NOAA G-scale, X-ray A/B, C, M, X). Band chips come from the in-process N0NBH cache and are labeledN0NBH. Sparklines use the SFI and Kp history already on the solar-indices payload. The image is rasterized with@resvg/resvg-wasm(no native addon, so Alpine, Pi, and the pkg binaries still work) and IBM Plex Sans, which is bundled because the production image has no system fonts.The badge reads
getSolarIndices()in-process — the same NOAA cache as/api/solar-indices— and does not call this server over HTTP. Renders are cached about five minutes per theme + fields + variant, concurrent misses share one render, and a missing upstream still returns a valid PNG that says "Data unavailable".?theme=accepts every OpenHamClock app theme (read fromsrc/styles/themes.css, so the colors stay in sync) plus red, blue, green, yellow, orange, purple, neutral, and neutral light. The default isdark, the app default.theme=redis the near-black /#e10600brand lockup. Unknown themes, fields, and sizes fall back to the defaults. Status greens, yellows, and reds stay semantic; the theme only changes the background and the accent.GET /api/badge/themeslists them./badges(also/badge-builder) is a builder in the existing app: pick fields, size, and theme, watch the PNG update, and copy QRZ HTML, generic HTML, Markdown, or BBCode. It is linked from Settings → Community and the Help footer.QRZ: Edit page → Biography tab → switch the editor to HTML / source view → paste → Save.
Type of change
How to test
npx vitest run server/badge/status.test.js server/routes/badge.test.js src/components/BadgeBuilder.test.jsx/badges. Confirm the preview is a PNG, then change the theme, uncheck a field, and switch to Compact. The image and the QRZ/HTML/Markdown/BBCode snippets should follow.curl -sI localhost:3001/api/badge/solar.pngshould showContent-Type: image/pngandCache-Control: public, max-age=300.Checklist
server.js: caches have TTLs and size caps (we serve 2,000+ concurrent users)var(--accent-cyan), etc.).bak,.old,console.logdebug lines, or test scripts includedThe builder page uses the app theme variables. The PNG itself has to bake colors in, including the semantic status colors, because it is a static image.
Screenshots (if visual change)
Builder (live NOAA data on this branch):
Badge builder
Theme switched to red; the snippet URL gains
theme=red:Builder with the red theme
Builder on a phone width
Badge samples (same conditions, different themes). Status colors stay put; the frame follows the theme.
Dark theme, the default
Red brand theme
Light theme
Retro theme
Matrix theme
Spring theme
Red theme with storm-level Kp (G2), poor SFI, and an M-class X-ray
Compact variant
To show artifacts inline, enable in settings.