From a6f4a931aff0595d16c04b89a357a3accc523e84 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 23 Aug 2025 18:46:00 +0200 Subject: [PATCH] Make sure no errors raised if source is nil or unknown --- app/helpers/trips_helper.rb | 2 ++ app/serializers/api/photo_serializer.rb | 2 ++ app/services/imports/create.rb | 2 ++ app/services/imports/watcher.rb | 4 +++- app/services/photos/thumbnail.rb | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb index 89f7771a..e035b53b 100644 --- a/app/helpers/trips_helper.rb +++ b/app/helpers/trips_helper.rb @@ -21,6 +21,8 @@ module TripsHelper immich_search_url(settings['immich_url'], start_date, end_date) when 'photoprism' photoprism_search_url(settings['photoprism_url'], start_date, end_date) + else + nil # return nil for nil or unknown source end end diff --git a/app/serializers/api/photo_serializer.rb b/app/serializers/api/photo_serializer.rb index c0a1119a..c21e9c6f 100644 --- a/app/serializers/api/photo_serializer.rb +++ b/app/serializers/api/photo_serializer.rb @@ -68,6 +68,8 @@ class Api::PhotoSerializer photo.dig('exifInfo', 'orientation') == '6' ? 'portrait' : 'landscape' when 'photoprism' photo['Portrait'] ? 'portrait' : 'landscape' + else + 'landscape' # default orientation for nil or unknown source end end end diff --git a/app/services/imports/create.rb b/app/services/imports/create.rb index 9b5417d0..1f952715 100644 --- a/app/services/imports/create.rb +++ b/app/services/imports/create.rb @@ -49,6 +49,8 @@ class Imports::Create private def importer(source) + return raise ArgumentError, 'Import source cannot be nil' if source.nil? + case source.to_s when 'google_semantic_history' then GoogleMaps::SemanticHistoryImporter when 'google_phone_takeout' then GoogleMaps::PhoneTakeoutImporter diff --git a/app/services/imports/watcher.rb b/app/services/imports/watcher.rb index 79e0a59c..6467ec06 100644 --- a/app/services/imports/watcher.rb +++ b/app/services/imports/watcher.rb @@ -70,12 +70,14 @@ class Imports::Watcher end def mime_type(source) - case source.to_sym + case source&.to_sym when :gpx then 'application/xml' when :json, :geojson, :google_phone_takeout, :google_records, :google_semantic_history 'application/json' when :owntracks 'application/octet-stream' + when nil + 'application/octet-stream' # fallback MIME type for nil source else raise UnsupportedSourceError, "Unsupported source: #{source}" end diff --git a/app/services/photos/thumbnail.rb b/app/services/photos/thumbnail.rb index 4f927aad..9ad4e57e 100644 --- a/app/services/photos/thumbnail.rb +++ b/app/services/photos/thumbnail.rb @@ -10,6 +10,7 @@ class Photos::Thumbnail end def call + raise ArgumentError, 'Photo source cannot be nil' if source.nil? raise unsupported_source_error unless SUPPORTED_SOURCES.include?(source) HTTParty.get(request_url, headers: headers)