Skip to content

Commit

Permalink
Add trace logging in uploadPhoto
Browse files Browse the repository at this point in the history
Trying to debug #15
  • Loading branch information
rcloran committed Mar 1, 2024
1 parent 8ce8ece commit 8a7f35f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lr-inaturalist-publish.lrdevplugin/Upload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local LrTasks = import("LrTasks")
local INaturalistAPI = require("INaturalistAPI")
local MetadataConst = require("MetadataConst")
local SyncObservations = require("SyncObservations")
local json = require("dkjson")

local Upload = {}

Expand Down Expand Up @@ -49,8 +50,10 @@ end

local function uploadPhoto(api, observations, rendition, path, exportSettings)
local observationUUID = rendition.photo:getPropertyForPlugin(_PLUGIN, MetadataConst.ObservationUUID)
logger:tracef("uploadPhoto. observationUUID = %s", observationUUID)

if observationUUID and observations[observationUUID] then
logger:tracef("Updating observation with UUID %s", observationUUID)
-- There's already an observation that was created this session. It's
-- faster to add an observation photo than upload photo then update the
-- observation.
Expand All @@ -70,11 +73,14 @@ local function uploadPhoto(api, observations, rendition, path, exportSettings)
-- the latter case it will be added to the list of observation_photos.
local photo = api:createPhoto(path)
LrFileUtils.delete(path)
logger:tracef("Created photo, got observation: %s", json.encode(photo.to_observation))
local observation = updateObservation(photo.to_observation, rendition.photo, exportSettings)
logger:tracef("Updated observation with photo metadata: %s", json.encode(observation))
-- Weirdly the `to_observation` included in the photo response doesn't
-- include the photo ID
observation.local_photos = { [0] = { photo.id } }
observation = api:createObservation(observation)
logger:tracef("createObservation response: %s", json.encode(observation))

return photo, observation
end
Expand Down

0 comments on commit 8a7f35f

Please sign in to comment.