From 1ac514293baf3d766deb96f199f18a8848829ea4 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:35:18 -0600 Subject: [PATCH 1/6] create static nginx docker build --- Dockerfile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d9c1c4c..5583756 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,16 @@ -FROM node:24-alpine +FROM node:24-alpine AS node-builder WORKDIR /app +# RUN npm install gulp + COPY package.json . COPY package-lock.json . -RUN npm ci - COPY . . -CMD ["node", "index.mjs"] + +RUN npm install +RUN npm run build + +FROM nginx:alpine +# COPY --from=node-builder /app/server /usr/share/nginx/html +COPY --from=node-builder /app/dist /usr/share/nginx/html From 2827913d42443aef40b916068f1ca3fd47b31c50 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 13 Jun 2025 08:37:01 -0600 Subject: [PATCH 2/6] add client-side generation for playlist.json for static builds --- Dockerfile | 7 +++-- README.md | 14 ++++++++-- nginx.conf | 20 +++++++++++++++ server/scripts/modules/media.mjs | 44 +++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 5583756..3ff3d52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,15 @@ FROM node:24-alpine AS node-builder WORKDIR /app -# RUN npm install gulp - COPY package.json . COPY package-lock.json . - COPY . . RUN npm install RUN npm run build +RUN rm dist/playlist.json FROM nginx:alpine -# COPY --from=node-builder /app/server /usr/share/nginx/html COPY --from=node-builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index 64f3218..9eee6e3 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,13 @@ npm run buildDist ``` The resulting files will be in the /dist folder in the root of the project. These can then be uploaded to a web server for hosting, no server-side scripting is required. +When using the provided Docker image, the browser will generate `playlist.json` +on the fly by scanning the `/music` directory served by nginx. The image +intentionally omits this file so the page falls back to scanning the directory. +Simply bind mount your music folder and the playlist will be created +automatically. If no files are found in `/music`, the built in tracks located in +`/music/default/` will be used instead. + ## What's different I've made several changes to this Weather Star 4000 simulation compared to the original hardware unit and the code that this was forked from. @@ -129,9 +136,12 @@ If you're looking for the original music that played during forecasts [TWCClassi ### Customizing the music Placing .mp3 files in the `/server/music` folder will override the default music included in the repo. Subdirectories will not be scanned. When weatherstar loads in the browser it will load a list if available files and randomize the order when it starts playing. On each loop through the available tracks the order will again be shuffled. If you're using the static files method to host your WeatherStar music is located in `/music`. -If using docker, you must pass a local accessible folder to the container in the `/app/server/music` directory. +If using docker, you can bind mount a local folder containing your music files. +Mount the folder at `/usr/share/nginx/html/music` so the browser can read the +directory listing and build the playlist automatically. If there are no `.mp3` +files in `/music`, the built in tracks from `/music/default/` are used. ``` -docker run -p 8080:8080 -v /path/to/local/music:/app/server/music ghcr.io/netbymatt/ws4kp +docker run -p 8080:8080 -v /path/to/local/music:/usr/share/nginx/html/music ghcr.io/netbymatt/ws4kp ``` ### Music doesn't auto play diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..207aac9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,20 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + + location / { + index index.html index.htm; + try_files $uri $uri/ =404; + } + + location /music/ { + autoindex on; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/server/scripts/modules/media.mjs b/server/scripts/modules/media.mjs index 235b6af..b44939a 100644 --- a/server/scripts/modules/media.mjs +++ b/server/scripts/modules/media.mjs @@ -1,4 +1,4 @@ -import { json } from './utils/fetch.mjs'; +import { json, text } from './utils/fetch.mjs'; import Setting from './utils/setting.mjs'; let playlist; @@ -19,18 +19,38 @@ document.addEventListener('DOMContentLoaded', () => { getMedia(); }); +const scanMusicDirectory = async () => { + const parseDirectory = async (path, prefix = "") => { + const listing = await text(path); + const matches = [...listing.matchAll(/href="([^\"]+\.mp3)"/gi)]; + return matches.map((m) => `${prefix}${m[1]}`); + }; + + try { + let files = await parseDirectory("music/"); + if (files.length === 0) { + files = await parseDirectory("music/default/", "default/"); + } + return { availableFiles: files }; + } catch (e) { + console.error("Unable to scan music directory"); + console.error(e); + return { availableFiles: [] }; + } +}; + + const getMedia = async () => { - try { - // fetch the playlist - const rawPlaylist = await json('playlist.json'); - // store the playlist - playlist = rawPlaylist; - // enable the media player - enableMediaPlayer(); - } catch (e) { - console.error("Couldn't get playlist"); - console.error(e); - } + try { + // fetch the playlist + const rawPlaylist = await json('playlist.json'); + playlist = rawPlaylist; + } catch (e) { + console.warn("Couldn't get playlist.json, falling back to directory scan"); + playlist = await scanMusicDirectory(); + } + + enableMediaPlayer(); }; const enableMediaPlayer = () => { From 3236b2ecc3214bb57f60b2a2e1bf2f060a26dae5 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 13 Jun 2025 09:04:39 -0600 Subject: [PATCH 3/6] radar fix for static deployment, slight spelling and grammer fixes in readme --- README.md | 25 ++++++++++++------------- gulp/publish-frontend.mjs | 4 ++-- server/scripts/modules/radar-worker.js | 1 + server/scripts/modules/radar.mjs | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 server/scripts/modules/radar-worker.js diff --git a/README.md b/README.md index 9eee6e3..8f49b18 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A live version of this project is available at https://weatherstar.netbymatt.com ## About -This project aims to bring back the feel of the 90's with a weather forecast that has the look and feel of The Weather Channel at that time but available in a modern way. This is by no means intended to be a perfect emulation of the WeatherStar 4000, the hardware that produced those wonderful blue and orange graphics you saw during the local forecast on The Weather Channel. If you would like a much more accurate project please see the [WS4000 Simulator](http://www.taiganet.com/). Instead, this project intends to create a simple to use interface with minimal configuration fuss. Some changes have been made to the screens available because either more or less forecast information is available today than was in the 90's. Most of these changes are captured in sections below. +This project aims to bring back the feel of the 90s with a weather forecast that has the look and feel of The Weather Channel at that time but available in a modern way. This is by no means intended to be a perfect emulation of the WeatherStar 4000, the hardware that produced those wonderful blue and orange graphics you saw during the local forecast on The Weather Channel. If you would like a much more accurate project please see the [WS4000 Simulator](http://www.taiganet.com/). Instead, this project intends to create a simple to use interface with minimal configuration fuss. Some changes have been made to the screens available because either more or less forecast information is available today than was in the 90s. Most of these changes are captured in sections below. ## What's your motivation @@ -76,7 +76,7 @@ services: ### Serving static files The app can be served as a static set of files on any web server. Run the provided gulp task to create a set of static distribution files: ``` -npm run buildDist +npm run build ``` The resulting files will be in the /dist folder in the root of the project. These can then be uploaded to a web server for hosting, no server-side scripting is required. @@ -95,13 +95,13 @@ I've made several changes to this Weather Star 4000 simulation compared to the o * A new hour-by-hour graph of the temperature, cloud cover and precipitation chances for the next 24 hours. * A new hourly forecast display for the next 24 hours is available, and is shown in the style of the travel cities forecast. (off by default because it duplicates the hourly graph) * The SPC Outlook is shown in the style of the old air quality screen. This shows the probability of severe weather over the next 3 days at your location. -* The "Local Forecast" and "Extended Forecast" provide several additional days of information compared to the original format in the 90's. +* The "Local Forecast" and "Extended Forecast" provide several additional days of information compared to the original format in the 90s. * The original music has been replaced. More info in [Music](#music). * Marine forecast (tides) is not available as it is not reliably part of the new API. * "Flavors" are not present in this simulation. Flavors refer to the order of the weather information that was shown on the original units. Instead, the order of the displays has been fixed and a checkboxes can be used to turn on and off individual displays. The travel forecast has been defaulted to off so only local information shows for new users. ## Sharing a permalink (bookmarking) -Selected displays, the forecast city and widescreen setting are sticky from one session to the next. However if you would like to share your exact configuration or bookmark it, click the "Copy Permalink" (or get "Get Parmalink") near the bottom of the page. A URL will be copied to your clipboard with all of you selected displays and location (or copy it from the page if your browser doesn't support clipboard transfers directly). You can then share this link or add it to your bookmarks. +Selected displays, the forecast city and widescreen setting are sticky from one session to the next. However if you would like to share your exact configuration or bookmark it, click the "Copy Permalink" (or get "Get Permalink") near the bottom of the page. A URL will be copied to your clipboard with all of you selected displays and location (or copy it from the page if your browser doesn't support clipboard transfers directly). You can then share this link or add it to your bookmarks. Your permalink will be very long. Here is an example for the Orlando International Airport: ``` @@ -119,24 +119,24 @@ Kiosk mode can be activated by a checkbox on the page. Note that there is no way It's also possible to enter kiosk mode using a permalink. First generate a [Permalink](#sharing-a-permalink-bookmarking), then to the end of it add `&kiosk=true`. Opening this link will load all of the selected displays included in the Permalink, enter kiosk mode immediately upon loading and start playing the forecast. -### Default query string paramaters (environment variables) -When serving this via the built-in Express server, it's possible to define environment variables that direct the user to a default set of paramaters (like the [Permalink](#sharing-a-permalink-bookmarking) above). If a user requests the root page at `http://localhost:8080/` the query string provided by environment variables will be appended to the url thus providing a default configuration. +### Default query string parameters (environment variables) +When serving this via the built-in Express server, it's possible to define environment variables that direct the user to a default set of parameters (like the [Permalink](#sharing-a-permalink-bookmarking) above). If a user requests the root page at `http://localhost:8080/` the query string provided by environment variables will be appended to the url thus providing a default configuration. Environment variables can be added to the command line as usual, or via a .env file which is parsed with [dotenv](https://github.com/motdotla/dotenv). Both methods have the same effect. -Environment variables that are to be added to the default query string are prefixed with `WSQS_` and then use the same key/value pairs generated by the [Permalink](#sharing-a-permalink-bookmarking) above, with the `- (dash)` character replaced by an `_ (underscore)`. For example, if you wanted to turn the travel forecast on, you would find `travel-checkbox=true` in the permalink, it's matching environment variable becomes `WSQS_travel_checkbox=true`. +Environment variables that are to be added to the default query string are prefixed with `WSQS_` and then use the same key/value pairs generated by the [Permalink](#sharing-a-permalink-bookmarking) above, with the `- (dash)` character replaced by an `_ (underscore)`. For example, if you wanted to turn the travel forecast on, you would find `travel-checkbox=true` in the permalink, its matching environment variable becomes `WSQS_travel_checkbox=true`. ## Music The WeatherStar had wonderful background music from the smooth jazz and new age genres by artists of the time. Lists of the music that played are available by searching online, but it's all copyrighted music and would be difficult to provide as part of this repository. -I've used AI tools to create WeatherStar-inspired music tracks that are unencumbered by copyright and are included in this repo. Too keep the size down, I've only included 4 tracks. Additional tracks are in a companion repository [ws4kp-music](https://github.com/netbymatt/ws4kp-music). +I've used AI tools to create WeatherStar-inspired music tracks that are unencumbered by copyright and are included in this repo. To keep the size down, I've only included 4 tracks. Additional tracks are in a companion repository [ws4kp-music](https://github.com/netbymatt/ws4kp-music). -If you're looking for the original music that played during forecasts [TWCClassics](https://twcclassics.com/audio/) has thurough documentation of playlists. +If you're looking for the original music that played during forecasts [TWCClassics](https://twcclassics.com/audio/) has thorough documentation of playlists. ### Customizing the music Placing .mp3 files in the `/server/music` folder will override the default music included in the repo. Subdirectories will not be scanned. When weatherstar loads in the browser it will load a list if available files and randomize the order when it starts playing. On each loop through the available tracks the order will again be shuffled. If you're using the static files method to host your WeatherStar music is located in `/music`. -If using docker, you can bind mount a local folder containing your music files. +If using Docker, you can bind mount a local folder containing your music files. Mount the folder at `/usr/share/nginx/html/music` so the browser can read the directory listing and build the playlist automatically. If there are no `.mp3` files in `/music`, the built in tracks from `/music/default/` are used. @@ -149,7 +149,7 @@ Ws4kp is muted by default, but if it was unmuted on the last visit it is coded t Chrome seems to be more lenient on auto play and will eventually let a site auto-play music if you're visited it enough recently and manually clicked to start playing music on each visit. It also has a flag you can add to the command line when launching Chrome: `chrome.exe --autoplay-policy=no-user-gesture-required`. This is the best solution when using Kiosk-style setup. -If you're unable to pre-set the play state before entering kiosk mode (such as with a home dashboard implemenation) you can add the query string value below to the url. The browser will still follow the auto play rules outlined above. +If you're unable to pre-set the play state before entering kiosk mode (such as with a home dashboard implementation) you can add the query string value below to the url. The browser will still follow the auto play rules outlined above. ``` ?settings-mediaPlaying-boolean=true ``` @@ -163,7 +163,7 @@ Thanks to the WeatherStar community for providing these discussions to further e * [ws4channels](https://github.com/rice9797/ws4channels) A Dockerized Node.js application to stream WeatherStar 4000 data into Channels DVR using Puppeteer and FFmpeg. ## Customization -A hook is provided as `/server/scripts/custom.js` to allow customizations to your own fork of this project, without accidentally pushing your customizations back upstream to the git repository. An sample file is provided at `/server/scripts/custom.sample.js` and should be renamed to `custom.js` activate it. +A hook is provided as `/server/scripts/custom.js` to allow customizations to your own fork of this project, without accidentally pushing your customizations back upstream to the git repository. A sample file is provided at `/server/scripts/custom.sample.js` and should be renamed to `custom.js` activate it. ## Issue reporting and feature requests @@ -197,4 +197,3 @@ This project is based on the work of [Mike Battaglia](https://github.com/vbguyny This web site should NOT be used in life threatening weather situations, or be relied on to inform the public of such situations. The Internet is an unreliable network subject to server and network outages and by nature is not suitable for such mission critical use. If you require such access to NWS data, please consider one of their subscription services. The authors of this web site shall not be held liable in the event of injury, death or property damage that occur as a result of disregarding this warning. The WeatherSTAR 4000 unit and technology is owned by The Weather Channel. This web site is a free, non-profit work by fans. All of the back ground graphics of this web site were created from scratch. The icons were created by Charles Abel and Nick Smith (http://twcclassics.com/downloads/icons.html) as well as by Malek Masoud. The fonts were originally created by Nick Smith (http://twcclassics.com/downloads/fonts.html). - diff --git a/gulp/publish-frontend.mjs b/gulp/publish-frontend.mjs index 0042b5a..8f19a5b 100644 --- a/gulp/publish-frontend.mjs +++ b/gulp/publish-frontend.mjs @@ -97,12 +97,12 @@ const buildJs = () => src(mjsSources) .pipe(dest(RESOURCES_PATH)); const workerSources = [ - 'server/scripts/modules/radar-worker.mjs', + 'server/scripts/modules/radar-worker.mjs', ]; const buildWorkers = () => { // update the file name in the webpack options - const output = { filename: 'radar-worker.mjs' }; + const output = { filename: 'radar-worker.js' }; const workerWebpackOptions = { ...webpackOptions, output }; return src(workerSources) .pipe(webpack(workerWebpackOptions)) diff --git a/server/scripts/modules/radar-worker.js b/server/scripts/modules/radar-worker.js new file mode 100644 index 0000000..4ea5e7a --- /dev/null +++ b/server/scripts/modules/radar-worker.js @@ -0,0 +1 @@ +import './radar-worker.mjs'; diff --git a/server/scripts/modules/radar.mjs b/server/scripts/modules/radar.mjs index 311483c..1c23623 100644 --- a/server/scripts/modules/radar.mjs +++ b/server/scripts/modules/radar.mjs @@ -197,7 +197,7 @@ class Radar extends WeatherDisplay { // create a radar worker with helper functions const radarWorker = () => { // create the worker - const worker = new Worker(`/resources/radar-worker.mjs?_=${version()}`, { type: 'module' }); + const worker = new Worker(`/resources/radar-worker.js?_=${version()}`, { type: 'module' }); const processRadar = (url) => new Promise((resolve, reject) => { // prepare for done message From 9f94ef83ba68021369b858278320e06772b28716 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:24:03 -0600 Subject: [PATCH 4/6] human readable song title --- server/scripts/modules/media.mjs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/scripts/modules/media.mjs b/server/scripts/modules/media.mjs index b44939a..b837ef5 100644 --- a/server/scripts/modules/media.mjs +++ b/server/scripts/modules/media.mjs @@ -188,8 +188,11 @@ const playerEnded = () => { }; const setTrackName = (fileName) => { - const trackName = fileName.replace(/\.mp3/gi, '').replace(/(_-)/gi, ''); - document.getElementById('musicTrack').innerHTML = trackName; + const baseName = fileName.split('/').pop(); + const trackName = decodeURIComponent( + baseName.replace(/\.mp3/gi, '').replace(/(_-)/gi, '') + ); + document.getElementById('musicTrack').innerHTML = trackName; }; export { From 6ff71228445b840bfd917c06fbe64a53171b0803 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 13 Jun 2025 14:33:06 -0600 Subject: [PATCH 5/6] env workaround for static build --- Dockerfile | 4 ++++ README.md | 4 ++++ nginx.conf | 4 ++-- static-env-handler.sh | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 static-env-handler.sh diff --git a/Dockerfile b/Dockerfile index 3ff3d52..081fbf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ RUN npm run build RUN rm dist/playlist.json FROM nginx:alpine + +COPY static-env-handler.sh /docker-entrypoint.d/01-static-env-handler.sh +RUN chmod +x /docker-entrypoint.d/01-static-env-handler.sh + COPY --from=node-builder /app/dist /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index 8f49b18..5d3ef60 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ Environment variables can be added to the command line as usual, or via a .env f Environment variables that are to be added to the default query string are prefixed with `WSQS_` and then use the same key/value pairs generated by the [Permalink](#sharing-a-permalink-bookmarking) above, with the `- (dash)` character replaced by an `_ (underscore)`. For example, if you wanted to turn the travel forecast on, you would find `travel-checkbox=true` in the permalink, its matching environment variable becomes `WSQS_travel_checkbox=true`. +When using the Docker container, these environment variables are read on container start-up to generate the static redirect HTML. + ## Music The WeatherStar had wonderful background music from the smooth jazz and new age genres by artists of the time. Lists of the music that played are available by searching online, but it's all copyrighted music and would be difficult to provide as part of this repository. @@ -165,6 +167,8 @@ Thanks to the WeatherStar community for providing these discussions to further e ## Customization A hook is provided as `/server/scripts/custom.js` to allow customizations to your own fork of this project, without accidentally pushing your customizations back upstream to the git repository. A sample file is provided at `/server/scripts/custom.sample.js` and should be renamed to `custom.js` activate it. +When using Docker, mount your `custom.js` file to `/usr/share/nginx/html/scripts/custom.js` to customize the static build. + ## Issue reporting and feature requests Please do not report issues with api.weather.gov being down. It's a new service and not considered fully operational yet. I've also observed that the API can go down on a regional basis (based on NWS office locations). This means that you may have problems getting data for, say, Chicago right now, but Dallas and others are working just fine. diff --git a/nginx.conf b/nginx.conf index 207aac9..c197c90 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,11 +1,11 @@ server { - listen 80; + listen 8080; server_name localhost; root /usr/share/nginx/html; location / { - index index.html index.htm; + index redirect.html index.html index.htm; try_files $uri $uri/ =404; } diff --git a/static-env-handler.sh b/static-env-handler.sh new file mode 100644 index 0000000..247c0e5 --- /dev/null +++ b/static-env-handler.sh @@ -0,0 +1,39 @@ +#!/bin/sh +set -eu + +ROOT="/usr/share/nginx/html" +QS="" + +# build query string from WSQS_ env vars +for var in $(env); do + case "$var" in + WSQS_*=*) + key="${var%%=*}" + val="${var#*=}" + key="${key#WSQS_}" + key="${key//_/-}" + if [ -n "$QS" ]; then + QS="$QS&${key}=${val}" + else + QS="${key}=${val}" + fi + ;; + esac +done + + +if [ -n "$QS" ]; then + cat > "$ROOT/redirect.html" < + + + + Redirecting + + + + +EOF +fi + +exec nginx -g 'daemon off;' From 51bb9696b02bbf61a3e9e30be446f560a36909e2 Mon Sep 17 00:00:00 2001 From: Mitchell Scott <10804314+rmitchellscott@users.noreply.github.com> Date: Fri, 13 Jun 2025 22:05:37 -0600 Subject: [PATCH 6/6] add x-weatherstar header for specific 404 detection --- README.md | 7 +++++++ nginx.conf | 2 ++ server/scripts/modules/media.mjs | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5d3ef60..8683319 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,13 @@ Simply bind mount your music folder and the playlist will be created automatically. If no files are found in `/music`, the built in tracks located in `/music/default/` will be used instead. +The nginx configuration also sets the `X-Weatherstar: true` header on all +responses. This uses `add_header ... always` so the header is sent even for +404 responses. When `playlist.json` returns a 404 with this header present, the +browser falls back to scanning the `/music` directory. If you host the static +files elsewhere, be sure to include this header so the playlist can be generated +automatically. + ## What's different I've made several changes to this Weather Star 4000 simulation compared to the original hardware unit and the code that this was forked from. diff --git a/nginx.conf b/nginx.conf index c197c90..a770d7e 100644 --- a/nginx.conf +++ b/nginx.conf @@ -4,6 +4,8 @@ server { root /usr/share/nginx/html; + add_header X-Weatherstar true always; + location / { index redirect.html index.html index.htm; try_files $uri $uri/ =404; diff --git a/server/scripts/modules/media.mjs b/server/scripts/modules/media.mjs index b837ef5..46e1395 100644 --- a/server/scripts/modules/media.mjs +++ b/server/scripts/modules/media.mjs @@ -1,4 +1,4 @@ -import { json, text } from './utils/fetch.mjs'; +import { text } from './utils/fetch.mjs'; import Setting from './utils/setting.mjs'; let playlist; @@ -42,9 +42,17 @@ const scanMusicDirectory = async () => { const getMedia = async () => { try { - // fetch the playlist - const rawPlaylist = await json('playlist.json'); - playlist = rawPlaylist; + const response = await fetch('playlist.json'); + if (response.ok) { + playlist = await response.json(); + } else if (response.status === 404 + && response.headers.get('X-Weatherstar') === 'true') { + console.warn("Couldn't get playlist.json, falling back to directory scan"); + playlist = await scanMusicDirectory(); + } else { + console.warn(`Couldn't get playlist.json: ${response.status} ${response.statusText}`); + playlist = { availableFiles: [] }; + } } catch (e) { console.warn("Couldn't get playlist.json, falling back to directory scan"); playlist = await scanMusicDirectory();