Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 42 additions & 23 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
# CHANGELOG

## 11-12-26
- The client now owns the dashboard state (active and known servers, link state, run state, the server's backup interval and retention, both versions) and pushes it to every open page on `GET /api/client/events`: one `snapshot` on subscribe, then `link`, `state`, `run-started`, `run-finished`, `servers`, `config`, `backups-changed`, `versions` and `ping`. `GET /api/client/dashboard` returns the same snapshot
- Link states: `LIVE` (the server's event stream is open), `DEGRADED` (no stream, because of an older server, the subscriber cap or a backoff, but the server answers its health check), `CONNECTING` (a server was just selected or its stream dropped and the first health check has not answered) and `DOWN` (no server, or the health check failed). While not `LIVE`, the client checks the server's health every 8 seconds, once per client instead of once per open page
- Pages no longer poll the server. Status, Backup Archives and Versions are driven by pushes, and the one-minute refresh only re-reads the client's stored state
- The Backup Archives table reloads when a run finishes, when the server announces `backups-changed` (archive deleted or backup location changed), when the connected server changes, and when the link comes back; on tab return or view return only if a server is connected and its link is up. While `DEGRADED` the client lists the server's archives once a minute and pushes `backups-changed` itself
- The client refetches the server's health on its `config-changed` event, so schedule and retention changes made elsewhere show up at once
- Versions: the client pushes its own update check result when it changes. The server's version is fetched when the link comes up (not again within 5 minutes of a good answer, unless the server was down) or the server changes, then at most hourly; it is asked again after 30 seconds if the server has not checked yet, 5 minutes after a server error and 10 minutes when unavailable. The Versions panel needs no recheck timer, and the server row reads "Unable to check" once the first check fails
- The page shows "Client unreachable" instead of "No server connected" when the client itself cannot be reached. Renewing the live connection does not trigger it: the page waits 8 seconds for the reconnect first. The Server Status panel says when live updates are unavailable from the server
- The Known Servers list updates on every open Dashboard the moment the client's list changes, including background discovery, and leaves a selection you are making alone. The Pickup Interval field is filled on the first successful load and never changed by pushes or refreshes
- When the connected server changes, including in the background, the Dashboard reloads at once, including the Server Config form
- Moved the Versions panel below the Backup Archives panel
- The event stream sends a `retry: 5000` hint and answers 503 with an empty body when 32 browsers are already subscribed
- `GET /api/client/status` no longer probes for the preferred server; background discovery does that, retrying every 4 seconds while no server is selected
- Removed the unused `GET /api/client/server-health` and `GET /api/client/versions`
- "Run Backup Now" now gives up waiting after `CLIENT_BACKUP_RUN_TIMEOUT` (default `PT6H`) instead of holding a request open forever; the client answers 504 saying the backup is probably still running on the server, and the dashboard still shows when it finishes
- Added a small `node --test` suite for the page's decision logic; `make test` runs it

## 11-11-26
- The client knows its own version (`0.1.0`) and checks GitHub for the latest release of `MediaGarrd/Client` shortly after starting and then once a day. `MEDIAGARRD_UPDATE_REPOSITORY`, `MEDIAGARRD_GITHUB_API_URL` and `MEDIAGARRD_UPDATE_CHECK_INTERVAL` change the repository, API address and interval; the interval must be at least `PT1H` or the client refuses to start
- Added a Versions panel to the Dashboard with a Server row and a Client row: "Up-to-date" when current, a red box with a link to the latest release when an update is available, muted when the check could not be made or no server is connected. The server's version comes from its `GET /api/v1/version`
- The Dashboard refreshes every minute while open and visible (Backup Archives, Known Servers without disturbing a selection, Versions from the stored status without contacting GitHub); the Pickup Interval field is never touched
- The client keeps one connection to the server's `GET /api/v1/events` and relays it on the new `GET /api/client/events` (`state`, `run-started`, `run-finished`, `ping`, and `link` for the stream's status). The Server Status "State" and the backup buttons switch to Running and back to Idle at once, and Backup Archives reloads when a run finishes
- The client resubscribes when the connected server changes, reconnects after a failure with a delay growing from 1 to 30 seconds, and reconnects when the stream is quiet for 45 seconds. A server without `/api/v1/events` is retried every 5 minutes and polled meanwhile
- The browser closes the live connection while the tab is hidden and reopens it on return; at most 32 browsers can subscribe
- A health check started before a live event no longer overwrites it with older information, and a slow Backup Archives reload no longer overwrites a newer one
- Scheduled tasks run on two threads, so a slow GitHub check cannot delay discovery or pickups

## 10-26-26
- Finished renaming the codebase to MediaGarrd
- Added issue templates, issue label and pull request workflows, and integration test workflows
- Added a `Makefile` with a `test` target
- Removed `install.sh`: `docker-compose.example.yml` now works as-is, the container keeps its downloads and state on the mounted volumes by default, and everything else is set from the web page
- `MEDIAGARRD_SERVER_PORT` now defaults to `38471` to match the server, and `MEDIAGARRD_SERVER_IP` is optional and accepts `<ip>:<port>`
- The client connects to `MEDIAGARRD_SERVER_IP` on its own at startup and keeps trying every 30 seconds until a server is selected, so scheduled pickups work without opening the web page
- Added a Server Config view, opened from the toggle in the top bar, that changes the connected server's backup location, interval, and retention count and adds, edits, and removes its services
- Split the web page into an HTML page, a stylesheet, and JavaScript modules
- Every API endpoint now returns errors as `{"error": "..."}`, passing on the server's own message and status code when the server rejects a request
- Fixed the server schedule being sent as a number of seconds instead of an ISO-8601 duration
- The Gradle wrapper is now committed so the project builds without a local Gradle install
- Network discovery finishes in a couple of seconds instead of minutes: it checks for an open port before making an HTTP request, probes many hosts at once, skips Docker and VPN interfaces, and only counts servers that answer with a MediaGarrd health response
- Connecting by IP accepts `host:port`, stops right away when the host is unreachable, and scans every port of a reachable host in about a second
- Fixed the connection badge being overwritten by the periodic health check while a scan or connection attempt is running
- The badge and status panel show when the selected server is not responding, the backup list says why it could not be loaded, and everything reloads on its own when the server comes back
- The backup list reloads when a backup run started elsewhere finishes, and the Dashboard shows saved server settings as soon as you switch back to it
- "Scan Local Network" reports how many servers the scan actually found
- Requests to the server now time out instead of hanging when it is unreachable, and health checks pause while the page is hidden
- Starting a download of a backup that is already downloading reuses the running download instead of writing the same file twice
- Unknown backups and download tasks return 404, invalid pickup intervals and server URLs return 400, and finished download tasks are forgotten after 10 minutes
- Backup file names from the server can no longer write outside the download directory
- The client state file is written atomically so a crash cannot leave it half written
- Removed unused code and dependencies
- Finished renaming the codebase to MediaGarrd; removed unused code and dependencies
- Added issue templates, issue label and pull request workflows, integration test workflows, and a `Makefile` with a `test` target. The Gradle wrapper is now committed
- Removed `install.sh`: `docker-compose.example.yml` works as-is, downloads and state stay on the mounted volumes by default, and everything else is set from the web page
- `MEDIAGARRD_SERVER_PORT` defaults to `38471` to match the server; `MEDIAGARRD_SERVER_IP` is optional and accepts `<ip>:<port>`. The client connects to it at startup and retries every 30 seconds until a server is selected, so scheduled pickups work without opening the page
- Added a Server Config view, opened from the toggle in the top bar, to change the connected server's backup location, interval and retention count and to add, edit and remove its services
- Split the web page into an HTML page, a stylesheet and JavaScript modules
- Every API endpoint returns errors as `{"error": "..."}`, passing on the server's own message and status code when it rejects a request. Unknown backups and download tasks return 404, invalid pickup intervals and server URLs return 400, and finished download tasks are forgotten after 10 minutes
- Fixed the server schedule being sent as seconds instead of an ISO-8601 duration
- Network discovery finishes in a couple of seconds: it checks for an open port before any HTTP request, probes many hosts at once, skips Docker and VPN interfaces, and counts only servers that answer with a MediaGarrd health response. "Scan Local Network" reports how many it found
- Connecting by IP accepts `host:port`, stops at once when the host is unreachable, and scans every port of a reachable host in about a second
- The badge and status panel show when the selected server is not responding, the backup list says why it could not load, and everything reloads when the server returns. The connection badge is no longer overwritten by the health check during a scan or connection attempt
- The backup list reloads when a run started elsewhere finishes, and the Dashboard shows saved server settings as soon as you switch back to it
- Requests to the server time out instead of hanging, and health checks pause while the page is hidden
- Starting a download of a backup that is already downloading reuses the running download
- Backup file names from the server can no longer write outside the download directory, and the client state file is written atomically
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

test:
./gradlew test --warning-mode all
node --test src/test/js/*.test.mjs

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,49 @@ The defaults in `docker-compose.yml` work as-is. To change them before the first
- **Server port to look for:** `MEDIAGARRD_SERVER_PORT` (default `38471`, the server's default). Discovery and "Connect by IP" try this port first.
- **Connect to a server automatically:** add `MEDIAGARRD_SERVER_IP=<server-ip>` (or `<server-ip>:<port>`) to `environment`. Until a server is selected, the client connects to this address as soon as it answers. Without it, pick a server in the web page.

`CLIENT_BACKUP_RUN_TIMEOUT` (ISO-8601, default `PT6H`, minimum `PT1M`; the client refuses to start below that) is how long "Run Backup Now" waits for the server to finish a backup. If it takes longer, the client answers 504 and the page shows an error; the backup keeps running on the server and the dashboard still shows when it finishes.

`CLIENT_PICKUP_INTERVAL` (ISO-8601, default `PT12H`) only sets the initial value. Once the interval has been saved in the web page, the stored value is used.

## Usage
- **Dashboard** connects to a MediaGarrd server by IP, from the list of known servers, or by scanning the local network. It shows the server's status, runs a backup, downloads backups, and sets how often the client downloads the latest backup on its own.
- **Server Config** changes the connected server's backup location, backup interval, and number of backups to keep, and adds, edits, and removes the services it backs up. The server must have finished its first-time setup (the `/config` page on the server) before it accepts changes from the client.

- **Live status and refresh**: the client keeps the dashboard state (active and known servers, link state, run state, the server's backup interval and retention, and both versions) and pushes every change to each open page through a live connection (see Live events). The Server Status "State" and the backup buttons change to Running the moment a run starts and back to Idle the moment it ends; the Backup Archives table reloads when a run finishes, when the server announces an archive change, when the connected server changes, and when the link comes back. The page does not poll the server. It re-reads the client's stored state once a minute and when a hidden tab becomes visible or the Dashboard is shown again, as a catch-all; the Backup Archives table is also reloaded then, but only when a server is connected and its link is up. A normal end of the live connection (it is renewed every few minutes) does not show "Client unreachable"; that appears only if the client stays unreachable for 8 seconds. The Pickup Interval field is only filled when the page loads and is never changed by pushes or refreshes.
- **Versions** panel on the Dashboard shows the client's and the connected server's version. Each checks GitHub for the latest release once a day. A row says "Up-to-date" when it is current, turns into a red box with a link to the latest release when an update is available, and is muted when the check could not be made (offline, rate limited) or no server is connected. The server needs to be a version that provides `GET /api/v1/version`.

Every setting is stored in the `./data/client/state` volume and survives restarts and container rebuilds.

### Finding servers
"Scan Local Network" checks every address of the networks the client is attached to, on `MEDIAGARRD_SERVER_PORT`, `38471`, `8080`, and `80`, and lists every MediaGarrd server that answers. "Connect by IP" also accepts `<ip>:<port>`, and scans every port of the host when the server is not on one of those ports.

With the default Docker networking the client only sees the container network, so a scan finds servers running on the same host but not on other machines. Use "Connect by IP" or `MEDIAGARRD_SERVER_IP` for those, or add `network_mode: host` to the service (and remove its `ports` mapping) so the scan covers your LAN.

## Update alerts
The Versions panel is driven by the `versions` event (`{"client": {...}, "server": {...} | null}`) and the `versions` field of `GET /api/client/dashboard`. Each status has `currentVersion`, `latestVersion`, `releaseUrl`, `updateAvailable`, `checkState` (`OK`, `NO_RELEASES`, `ERROR`, `NOT_CHECKED`, or `UNAVAILABLE` when the server cannot be asked), `checkedAt`, and `message`. `server` is `null` while no server is selected.

To change what is checked, set `MEDIAGARRD_UPDATE_REPOSITORY` (default `MediaGarrd/Client`), `MEDIAGARRD_GITHUB_API_URL` (default `https://api.github.com`), or `MEDIAGARRD_UPDATE_CHECK_INTERVAL` (ISO-8601, default `PT24H`, minimum `PT1H`) in `environment`.

## Live events
`GET /api/client/events` is a Server-Sent Events stream for the web page, and `GET /api/client/dashboard` returns the same state as one JSON snapshot without contacting the server. The client keeps one connection to the connected server's `GET /api/v1/events`, owns the dashboard state, and pushes it. Every new subscriber first gets one `snapshot`, followed by granular events:
- `snapshot` `{"activeServer": "<url or null>", "knownServers": [...], "link": "LIVE|DEGRADED|CONNECTING|DOWN", "running": bool or null, "health": {"backupInterval": "PT6H", "backupRetentionCount": 5} or null, "versions": {"client": {...}, "server": {...} or null}}`: the whole state. Also sent to everyone when the active server changes.
- `link` `{"server": "<url or empty>", "state": "LIVE|DEGRADED|CONNECTING|DOWN"}`.
- `LIVE`: the server's event stream is open, and run state is pushed.
- `DEGRADED`: no event stream (an older server, the server at its subscriber cap, or a reconnect backoff), but the server answers `GET /api/v1/health`. The client polls it every 8 seconds, once per client no matter how many pages are open, and synthesizes `state` events from it. The poll stops when the link is `LIVE`.
- `CONNECTING`: a server was just selected, or its stream just dropped, and the first health check has not answered yet. Run state is unknown.
- `DOWN`: no active server, or no event stream and the last health check failed. Run state is unknown (`running` is `null`) and the client keeps checking.
- `state` `{"running": bool, "at": "<ISO-8601>"}`, `run-started` `{"running": true, "startedAt": "..."}` and `run-finished` `{"running": false, "status": "COMPLETED|PARTIAL|FAILED", "startedAt": "...", "finishedAt": "..."}`: forwarded from the server.
- `backups-changed` `{"at": "<ISO-8601>"}`: forwarded from the server when its archive list changed outside a run (an archive was deleted or the backup location changed). While the link is `DEGRADED` the client lists the server's archives once a minute and sends this itself when the list changed, so open pages never ask the server.
- `config` `{"backupInterval": "PT6H", "backupRetentionCount": 5}`: the server's schedule or retention. The client refetches the server's health when the server announces `config-changed`, on link up, and once a minute while the link is `LIVE`, and pushes this only when the values changed.
- `servers` `{"knownServers": [...], "activeServer": "<url or null>"}`: the client's list of known servers changed (discovery, a scan, a connect).
- `versions` `{"client": {...}, "server": {...} or null}`: the client's update check result changed, or the server's version was fetched. The server's version is fetched when the link comes up (unless it was fetched successfully in the last 5 minutes and the server was not down in between) or the server changes, and at most hourly after that. A version the server has not checked yet is asked for again after 30 seconds, an error after 5 minutes, and an unavailable one after 10 minutes.
- `ping` `{}` every 20 seconds.

The first event on each stream carries `retry: 5000`, so a browser that loses the client waits 5 seconds before reconnecting. The client reconnects to the server with a growing delay (1 to 30 seconds), resubscribes when the connected server changes, and drops a stream that has been silent for 45 seconds. A server that answers 404 (older than this feature) is tried again every 5 minutes and is `DEGRADED` meanwhile. At most 32 browsers can subscribe at once (further requests get an empty 503). If a reverse proxy sits in front, the response sends `Cache-Control: no-cache` and `X-Accel-Buffering: no`; do not buffer it.

## Tests
`make test` runs the Java tests (`./gradlew test`) and the browser tests. The browser tests need Node 20.19 or newer, have no dependencies, and can be run on their own with `node --test src/test/js/*.test.mjs`. They cover the pure modules in `src/main/resources/static/js`: `dashboard-model.js` (event reduction and what triggers a reload), `view-model.js` (link state, known servers and versions rendering decisions) and `reachability.js` (when the client counts as unreachable).

## Updating
```bash
git pull
Expand Down
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
id("io.spring.dependency-management") version "1.1.6"
}

version = "0.1.0"

repositories {
mavenCentral()
}
Expand All @@ -21,6 +23,10 @@ java {
}
}

springBoot {
buildInfo()
}

tasks.test {
useJUnitPlatform()
}
Loading
Loading