Fix owntracks point creation

This commit is contained in:
Eugene Burmakin 2025-07-20 17:43:55 +02:00
parent 45713f46dc
commit 708bca26eb
6 changed files with 54 additions and 40 deletions

View file

@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Fixed
- Swagger documentation is now valid again.
- Invalid owntracks points are now ignored.
# [0.29.1] - 2025-07-02

View file

@ -8,7 +8,7 @@ class Owntracks::PointCreatingJob < ApplicationJob
def perform(point_params, user_id)
parsed_params = OwnTracks::Params.new(point_params).call
return if parsed_params[:timestamp].nil? || parsed_params[:lonlat].nil?
return if parsed_params.try(:[], :timestamp).nil? || parsed_params.try(:[], :lonlat).nil?
return if point_exists?(parsed_params, user_id)
Point.create!(parsed_params.merge(user_id:))

View file

@ -10,6 +10,8 @@ class OwnTracks::Params
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def call
return unless valid_point?
{
lonlat: "POINT(#{params[:lon]} #{params[:lat]})",
battery: params[:batt],
@ -84,4 +86,8 @@ class OwnTracks::Params
def owntracks_point?
params[:topic].present?
end
def valid_point?
params[:lon].present? && params[:lat].present? && params[:tst].present?
end
end

View file

@ -28,5 +28,13 @@ RSpec.describe Owntracks::PointCreatingJob, type: :job do
expect { perform }.not_to(change { Point.count })
end
end
context 'when point is invalid' do
let(:point_params) { { lat: 1.0, lon: 1.0, tid: 'test', tst: nil, topic: 'iPhone 12 pro' } }
it 'does not create a point' do
expect { perform }.not_to(change { Point.count })
end
end
end
end

View file

@ -185,5 +185,13 @@ RSpec.describe OwnTracks::Params do
expect(params[:trigger]).to eq('unknown')
end
end
context 'when point is invalid' do
let(:raw_point_params) { super().merge(lon: nil, lat: nil, tst: nil) }
it 'returns parsed params' do
expect(params).to eq(nil)
end
end
end
end

View file

@ -1059,18 +1059,14 @@ paths:
type: string
example: your-photoprism-api-key
description: API key for PhotoPrism photo service
maps:
type: object
properties:
distance_unit:
type: string
example: km
description: Distance unit preference (km or miles)
description: Map-related settings
visits_suggestions_enabled:
type: boolean
example: true
description: Whether visit suggestions are enabled
speed_color_scale:
type: string
example: viridis
description: Color scale for speed-colored routes
fog_of_war_threshold:
type: number
example: 100
description: Fog of war threshold value
examples:
'0':
summary: Updates user settings
@ -1090,9 +1086,8 @@ paths:
immich_api_key: your-immich-api-key
photoprism_url: https://photoprism.example.com
photoprism_api_key: your-photoprism-api-key
maps:
distance_unit: km
visits_suggestions_enabled: true
speed_color_scale: viridis
fog_of_war_threshold: 100
get:
summary: Retrieves user settings
tags:
@ -1116,28 +1111,28 @@ paths:
type: object
properties:
route_opacity:
type: string
example: '60'
type: number
example: 60
description: Route opacity percentage (0-100)
meters_between_routes:
type: string
example: '500'
type: number
example: 500
description: Minimum distance between routes in meters
minutes_between_routes:
type: string
example: '30'
type: number
example: 30
description: Minimum time between routes in minutes
fog_of_war_meters:
type: string
example: '50'
type: number
example: 50
description: Fog of war radius in meters
time_threshold_minutes:
type: string
example: '30'
type: number
example: 30
description: Time threshold for grouping points in minutes
merge_threshold_minutes:
type: string
example: '15'
type: number
example: 15
description: Threshold for merging nearby points in minutes
preferred_map_layer:
type: string
@ -1172,18 +1167,14 @@ paths:
type: string
example: your-photoprism-api-key
description: API key for PhotoPrism photo service
maps:
type: object
properties:
distance_unit:
type: string
example: km
description: Distance unit preference (km or miles)
description: Map-related settings
visits_suggestions_enabled:
type: boolean
example: true
description: Whether visit suggestions are enabled
speed_color_scale:
type: string
example: viridis
description: Color scale for speed-colored routes
fog_of_war_threshold:
type: number
example: 100
description: Fog of war threshold value
"/api/v1/stats":
get:
summary: Retrieves all stats