Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

831 B
Raw Blame
import { googleRoutePreviewSchema, type GoogleRouteImport } from '@trek/shared'
import { apiClient } from '../api/client'
import { isEffectivelyOffline } from '../sync/networkMode'

export const googleRouteRepo = {
  async preview(url: string, signal: AbortSignal) {
    if (isEffectivelyOffline()) throw new Error('Import requires a connection')
    const reply = await apiClient.post('/roadtrip/google-maps-preview', { url }, { signal, timeout: 120000 })
    return googleRoutePreviewSchema.parse(reply.data)
  },
  async append(tripId: number, input: GoogleRouteImport, idempotencyKey: string) {
    if (isEffectivelyOffline()) throw new Error('Import requires a connection')
    await apiClient.post(`/trips/${tripId}/roadtrip/google-maps-import`, input, {
      headers: { 'X-Idempotency-Key': idempotencyKey },
    })
  },
}