mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
94c369b913
Journey Settings get "Prepare recorded days automatically" under GPX Tracks, off by default and set by the owner. With it on, the Dawarich background check also reads the linked trips of the journey for the owner and every editor with a connection of their own, within the same 400 day reach and windows as the trip sync, and only for new and changed stays: a trip the person travels on is not asked twice, and the stays of a trip they are not on are filed under no trip. Nothing is written into the journey; the stays wait at their day, and a stay taken over or left out is never offered again. Under the switch the caller sees when their stays were last fetched, or why not (no connection, no dated trip, background check off, the reason of the last failure beside the state still shown), with a "Fetch now" that the switch also runs when it is turned on. A day of the trips that is not final yet carries a dot on its take-over button, on the phone in the stay sheet, and the tooltip says whether it is still running, was fetched before it ended, was not fetched yet or shows an older state after a failed refresh. The day review says so for today too. Server: migration 046180 adds journeys.auto_prepare_recordings and journey_recording_prep (the last attempt, last success and last error per journey and person). JourneyRecordingPrepService in the journey domain lists the prepared trips and keeps the status; DawarichSyncService walks those trips in the same loop as the person's own and records each journey's outcome. GET /api/journeys/:id/recordings/prep answers the caller's status under a @trek/shared contract, the MCP tool get_journey_recording_prep reads the same, and update_journey takes auto_prepare_recordings like the PUT contract. The column stays out of the plugin output. All 27 locales carry the strings; the Journey, Dawarich and MCP tool wiki pages describe it.
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import {
|
|
dawarichAtlasSuggestionsSchema,
|
|
dawarichBucketScanSchema,
|
|
dawarichSuggestionListSchema,
|
|
dawarichTrackSchema,
|
|
} from '@trek/shared'
|
|
import { dawarichApi } from '../api/dawarich'
|
|
import { isEffectivelyOffline } from '../sync/networkMode'
|
|
|
|
/**
|
|
* Reads from the Dawarich integration.
|
|
*
|
|
* **Deliberately online-only, and no Dexie table.** Everything here is a live
|
|
* read of somebody's location history on a server TREK does not own: a cached
|
|
* recording is a stale one, and a cached copy of a GPS archive is the thing
|
|
* this integration exists not to keep. The precedent in this directory is
|
|
* `roadtripHazardsRepo` / `chargingRepo` / `schoolHolidayCatalogRepo` — same
|
|
* shape, same reason.
|
|
*
|
|
* The offline check is `isEffectivelyOffline()` rather than `navigator.onLine`,
|
|
* so the manual offline switch counts: someone who turned it on before a flight
|
|
* has said they do not want requests fired, and firing them anyway would block
|
|
* the UI on a timeout.
|
|
*
|
|
* Responses are parsed against the shared schema rather than cast. A server
|
|
* that answered something unexpected should fail here, loudly, not three
|
|
* components later where the cause is invisible.
|
|
*/
|
|
|
|
/** Thrown before a request is made when the device is offline by choice or by circumstance. */
|
|
export class DawarichOfflineError extends Error {
|
|
constructor() {
|
|
super('Dawarich needs a connection')
|
|
this.name = 'DawarichOfflineError'
|
|
}
|
|
}
|
|
|
|
function requireOnline(): void {
|
|
if (isEffectivelyOffline()) throw new DawarichOfflineError()
|
|
}
|
|
|
|
export const dawarichRepo = {
|
|
async suggestions(params?: { tripId?: number; state?: string }) {
|
|
requireOnline()
|
|
return dawarichSuggestionListSchema.parse(await dawarichApi.listSuggestions(params))
|
|
},
|
|
|
|
async tripTrack(tripId: number, range?: { from?: string; to?: string }, signal?: AbortSignal) {
|
|
requireOnline()
|
|
return dawarichTrackSchema.parse(await dawarichApi.tripTrack(tripId, range, signal))
|
|
},
|
|
|
|
async windowTrack(from: string, to: string, signal?: AbortSignal) {
|
|
requireOnline()
|
|
return dawarichTrackSchema.parse(await dawarichApi.windowTrack(from, to, signal))
|
|
},
|
|
|
|
async bucketScan() {
|
|
requireOnline()
|
|
return dawarichBucketScanSchema.parse(await dawarichApi.scanBucketList())
|
|
},
|
|
|
|
/** Asks for a sync now instead of at the next tick; a second one while it runs is answered, not started. */
|
|
async syncNow() {
|
|
requireOnline()
|
|
return await dawarichApi.syncNow()
|
|
},
|
|
|
|
async atlasSuggestions(from: string, to: string) {
|
|
requireOnline()
|
|
return dawarichAtlasSuggestionsSchema.parse(await dawarichApi.atlasSuggestions(from, to))
|
|
},
|
|
}
|