Skip to content

Commit 4841f76

Browse files
authored
feat: convert user configuration to YAML (#94)
Co-authored-by: Borewit <Borewit@users.noreply.github.com>
1 parent a6b6e3e commit 4841f76

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
**/node_modules
22
package-lock.json
3+
4+
# User configuration
5+
public/config.yaml

docs/server.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ You can also run the app locally with Node.js - see the [Building audioMotion](b
1414
!> **Playlists, Presets and Custom gradients** are saved to the browser's storage and will only be accessible in the same browser they were saved.
1515
The storage is also tied to the server **address and port**, so if any of those change, data saved on a different address/port won't be accessible.
1616

17-
## config.json file
17+
## config.yaml file
1818

19-
A **config.json** file in the same directory as audioMotion's _index.html_ allows you to configure some server options.
19+
A **config.yaml** file in the same directory as audioMotion's _index.html_ allows you to configure some server options.
2020

21-
```config.json
21+
```yaml
2222
{
23-
"defaultAccessMode": "local",
24-
"enableLocalAccess": true,
25-
"frontPanel": "open"
23+
defaultAccessMode: local
24+
enableLocalAccess: true
25+
frontPanel: open
2626
}
2727
```
2828

@@ -40,7 +40,7 @@ The following URL parameters can also be used when accessing audioMotion:
4040
|-----------|-----------------|-------------|
4141
| **debug** | *none* | If present in the URL, app starts in [debug mode](users-manual.md#debug), which may help identify issues during the initialization stage
4242
| **mode** | `local` \| `server` | Starts audioMotion in the desired access mode (local access must be enabled on the server)
43-
| **frontPanel** | `open` \| `close` | Same as the corresponding `config.json` option, but overrides the server configuration
43+
| **frontPanel** | `open` \| `close` | Same as the corresponding `config.yaml` option, but overrides the server configuration
4444

4545
Use an **&** character to separate multiple parameters. Example usage:
4646

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"css-minimizer-webpack-plugin": "^7.0.0",
1818
"http-server": "^14.1.1",
1919
"idb-keyval": "^6.2.1",
20+
"js-yaml": "^4.1.0",
2021
"mini-css-extract-plugin": "^2.9.0",
2122
"music-metadata-browser": "^2.5.10",
2223
"notie": "^4.3.1",

public/config.json.example

Lines changed: 0 additions & 5 deletions
This file was deleted.

public/config.yaml.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Initial (first run) file access mode - user’s device or /music directory on serve
2+
# local | server
3+
defaultAccessMode: local
4+
5+
# Whether to enable access to local device (true allows user to switch between local or server)
6+
# true | false
7+
enableLocalAccess: true
8+
9+
# Initial state of the Media Panel (“close” expands the analyzer area)
10+
# open | close
11+
frontPanel: open

src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import * as fileExplorer from './file-explorer.js';
3535
import * as mm from 'music-metadata-browser';
3636
import './scrollIntoViewIfNeeded-polyfill.js';
3737
import { get, set, del } from 'idb-keyval';
38+
import * as yaml from 'js-yaml';
3839

3940
import Sortable, { MultiDrag } from 'sortablejs';
4041
Sortable.mount( new MultiDrag() );
@@ -156,7 +157,7 @@ const OSD_SIZE_S = '0',
156157
OSD_SIZE_M = '1',
157158
OSD_SIZE_L = '2';
158159

159-
// Valid values for the `frontPanel` URL parameter and config.json option
160+
// Valid values for the `frontPanel` URL parameter and config.yaml option
160161
const PANEL_CLOSE = 'close',
161162
PANEL_OPEN = 'open';
162163

@@ -208,7 +209,7 @@ const SCALEXY_OFF = 0,
208209
SCALEX_NOTES = 2;
209210

210211
// Server configuration filename and default values
211-
const SERVERCFG_FILE = 'config.json',
212+
const SERVERCFG_FILE = 'config.yaml',
212213
SERVERCFG_DEFAULTS = {
213214
defaultAccessMode: FILEMODE_LOCAL,
214215
enableLocalAccess: true,
@@ -837,7 +838,7 @@ let audioElement = [],
837838
randomModeTimer,
838839
serverHasMedia, // music directory found on web server
839840
skipping = false,
840-
supportsFileSystemAPI, // browser supports File System API (may be disabled via config.json)
841+
supportsFileSystemAPI, // browser supports File System API (may be disabled via config.yaml)
841842
useFileSystemAPI, // load music from local device when in web server mode
842843
userPresets,
843844
waitingMetadata = 0,
@@ -5179,17 +5180,18 @@ function updateRangeValue( el ) {
51795180
}
51805181
}
51815182

5182-
// Load server configuration options from config.json
5183+
// Load server configuration options from config.yaml
51835184
let response;
51845185

51855186
try {
51865187
response = await fetch( SERVERCFG_FILE );
51875188
}
51885189
catch( e ) {}
51895190

5190-
let serverConfig = response && response.ok ? await response.text() : '{}';
5191+
let serverConfig = response && response.ok ? await response.text() : '';
5192+
51915193
try {
5192-
serverConfig = JSON.parse( serverConfig );
5194+
serverConfig = yaml.load(serverConfig);
51935195
}
51945196
catch( err ) {
51955197
consoleLog( `Error parsing ${ SERVERCFG_FILE } - ${ err }`, true );

0 commit comments

Comments
 (0)