Make sure no errors raised if source is nil or unknown

This commit is contained in:
Eugene Burmakin 2025-08-23 18:46:00 +02:00
parent 6491d0433a
commit a6f4a931af
5 changed files with 10 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)