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
This commit is contained in:
1 parent
850a5946ad
commit
dbe742321a
13 files changed
+460
-5
No files matched your search
@@ -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;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
mdiBugOutline,
|
||||
mdiClockOutline,
|
||||
mdiCloudDownloadOutline,
|
||||
mdiCloudSyncOutline,
|
||||
mdiContentSaveOutline,
|
||||
mdiCrosshairsGps,
|
||||
mdiDeleteSweepOutline,
|
||||
@@ -58,6 +59,7 @@ export const RADAR_CLOUD_ICON = mdi(mdiRadar);
|
||||
export const TERRAIN_SHADOW_ICON = mdi(mdiSunAngleOutline);
|
||||
export const CONTOUR_ICON = mdi(mdiBacteriaOutline);
|
||||
export const OFFLINE_DATA_ICON = mdi(mdiCloudDownloadOutline);
|
||||
export const SYNC_ICON = mdi(mdiCloudSyncOutline);
|
||||
export const DEBUG_ICON = mdi(mdiBugOutline);
|
||||
export const WIKI_ICON = mdi(mdiWikipedia);
|
||||
export const LIVETRACK_ICON = mdi(mdiMapMarkerRadiusOutline);
|
||||
|
||||
Reference in new issue
Block a user