mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-14 07:39:29 -07:00
add x-weatherstar header for specific 404 detection
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user