Library sync OsmAnd-style: brick is the server, a client (the car's maptool, SYNC_SERVER_URL) syncs on its Sync button — pulls the server's rows, pushes its own with the source files the server lacks, newer updated_at wins; /api/sync/* guarded by SYNC_TOKEN (written into brick's .env by CI). TRUSTED_NETWORKS logs in the car's LAN (no Gitea offline); TAKEOUT_HOST_DIR for a server without the Takeout; bin/pull-maps.sh pulls map data one way while at home
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-27 23:22:32 +01:00
1 parent 850a5946ad
commit dbe742321a
13 files changed
+460 -5

No files matched your search

+30
View File
@@ -8,6 +8,7 @@ import {
TRACK_ICON,
ROUTE_ICON,
DOWNLOAD_ICON,
SYNC_ICON,
MAP_MARKER_ICON,
POI_ICONS,
PARK4NIGHT_TAGS,
@@ -134,6 +135,17 @@ export class GpxPanelControl {
// The top level's own items have no folder row with a menu of its own.
const close = this._panel.querySelector(".gpx-panel__close");
close.before(this._menuButton(DOWNLOAD_ICON, "Export the top level", this._exportEntries("", "MapTool")));
// A sync client (the car's server) syncs with the main one on demand.
if ("syncClient" in this._panel.dataset) {
const sync = document.createElement("button");
sync.type = "button";
sync.className = "gpx-panel__action";
sync.title = "Sync with the main server";
sync.setAttribute("aria-label", sync.title);
sync.innerHTML = SYNC_ICON;
sync.addEventListener("click", () => this._sync(sync));
close.before(sync);
}
}
this._panel
.querySelector(".gpx-panel__close")
@@ -1403,6 +1415,24 @@ export class GpxPanelControl {
}
}
async _sync(button) {
button.disabled = true;
this._setStatus("Syncing…");
try {
const response = await fetch("/api/sync/run", { method: "POST" });
if (redirectIfUnauthorized(response)) return;
const body = await response.json();
if (!response.ok) return this._setStatus(body.error || "Sync failed.");
this._setStatus(`Synced: ${body.pulled} from the server, ${body.pushed} sent.`);
await this._loadTree();
await Promise.all([...this._visible].map((path) => this._reloadFile(path)));
} catch {
this._setStatus("Sync failed: the server is unreachable.");
} finally {
button.disabled = false;
}
}
_setStatus(text) {
this._uploadStatus.hidden = false;
this._uploadStatus.textContent = text;