Skip to content

Commit

Permalink
fixed the sets behaviour for the lightroom plugin -- renaming is cont…
Browse files Browse the repository at this point in the history
…ingent on #60547544 being deployed
  • Loading branch information
seanmdick committed Nov 11, 2013
1 parent 7a9774e commit 49398e5
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.DS_STORE
87 changes: 80 additions & 7 deletions StippleAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end

--------------------------------------------------------------------------------

function StippleAPI.callRestMethod( propertyTable, params )
function StippleAPI.getRestMethod( propertyTable, params )
local apiKey = StippleAPI.getApiKeyAndSecret()

if not params.api_key then
Expand Down Expand Up @@ -239,11 +239,66 @@ end

--------------------------------------------------------------------------------

function StippleAPI.postRestMethod( propertyTable, params )
assert( type( params ) == 'table', 'StippleAPI.postRestMethod: params must be a table' )
local apiKey = StippleAPI.getApiKeyAndSecret()
local url = string.format( urlBase .. '/api/v1/%s', assert( params.url ) )
params.url = nil

if not params.api_key then
params.api_key = apiKey
end

local suppressError = params.suppressError
local suppressErrorCodes = params.suppressErrorCodes
local skipAuthToken = params.skipAuthToken

params.suppressError = nil
params.suppressErrorCodes = nil
params.skipAuthToken = nil
local chunks = {}

for key, value in pairs(params) do
if (type(value) == 'table') then
for attribute, val in pairs(value) do
if (type(attribute) == 'number') then
attribute = ''
end
table.insert(chunks, { name = key .. '[' .. attribute .. ']', value = val })
end
else
table.insert(chunks, {name = key, value = value })
end
end

local response, hdrs = LrHttp.postMultipart( url, chunks ) -- Post it and wait for confirmation.

if not response then
if hdrs and hdrs.error then
LrErrors.throwUserError( formatError( hdrs.error.nativeCode ) )
end
end

local json = JSON:decode(response)
if tonumber(json.status) == 200 then
return json
else
return json
end
end

--------------------------------------------------------------------------------

function StippleAPI.uploadPhoto( propertyTable, params )
assert( type( params ) == 'table', 'StippleAPI.uploadPhoto: params must be a table' )

local apiKey = StippleAPI.getApiKeyAndSecret()
local postUrl = params.id and urlBase .. '/api/v1/photos/update' or urlBase .. '/api/v1/photos/upload/'
local postUrl = ''
if not not params.id then
postUrl = urlBase .. '/api/v1/photos/update'
else
postUrl = urlBase .. '/api/v1/photos/upload/'
end
local originalParams = params.id and table.shallowcopy( params )

logger:info( 'uploading photo', params.filePath )
Expand Down Expand Up @@ -281,7 +336,7 @@ function StippleAPI.uploadPhoto( propertyTable, params )
local json = JSON:decode(response)

if tonumber(json.status) == 200 then
return json.data.photo.id
return tostring(json.data.photo.id)
elseif params.id and json.error and tonumber(hdrs.error.nativeCode) == 422 then
-- Photo is missing. Most likely, the user deleted it outside of Lightroom. Just repost it.

Expand All @@ -299,7 +354,7 @@ end
--------------------------------------------------------------------------------

function StippleAPI.openAuthUrl()
local response = StippleAPI.callRestMethod( nil, { url = 'users/me' } )
local response = StippleAPI.getRestMethod( nil, { url = 'users/me' } )

return response.data
end
Expand Down Expand Up @@ -337,13 +392,26 @@ end
--------------------------------------------------------------------------------

function StippleAPI.createOrUpdatePhotoset( propertyTable, params )
return true
local response = {}
if params.photosetId then
StippleAPI.postRestMethod(nil, { url = "sets/update", id = params.photosetId, set = { name = params.title } })
return params.photosetId, StippleAPI.constructPhotosetURL(propertyTable, params.photosetId)
end

response = StippleAPI.postRestMethod(nil, { url = "sets/create", set = params })

return tostring(response.data.set.id), StippleAPI.constructPhotosetURL(propertyTable, tostring(response.data.set.id))
end

--------------------------------------------------------------------------------

function StippleAPI.listPhotosFromPhotoset( propertyTable, params )
return nil
local response, ids = {}, {}
response = StippleAPI.getRestMethod(nil, {url = 'sets/' .. params.photosetId})
for _,photo in pairs(response.data.set.photos) do
table.insert(ids,photo.id)
end
return ids
end

--------------------------------------------------------------------------------
Expand All @@ -355,18 +423,23 @@ end
--------------------------------------------------------------------------------

function StippleAPI.addPhotosToSet( propertyTable, params )
local data = {}
data = StippleAPI.postRestMethod(nil, { url = 'sets/add', id = params.photosetId, photo_ids = params.photoId })
return true
end

--------------------------------------------------------------------------------

function StippleAPI.deletePhoto( propertyTable, params )
function StippleAPI.deletePhotoFromPhotoset( propertyTable, params )
local data = {}
data = StippleAPI.postRestMethod(nil, { url = 'sets/remove', id = params.photosetId, photo_ids = params.photoId })
return true
end

--------------------------------------------------------------------------------

function StippleAPI.deletePhotoset( propertyTable, params )
data = StippleAPI.postRestMethod(nil, {url = 'sets/delete', id = params.photosetId})
return true
end

Expand Down
49 changes: 24 additions & 25 deletions StippleExportServiceProvider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon
progressScope:setPortionComplete( ( i - 1 ) / nPhotos ) -- Update progress scope.

local photo = rendition.photo -- Get next photo.
local stipplePhotoId = stipplePhotoIdsForRenditions[rendition] -- See if we previously uploaded this photo.
local stipplePhotoId = rendition.publishedPhotoId -- See if we previously uploaded this photo.

if not rendition.wasSkipped then
local success, pathOrMessage = rendition:waitForRender() -- Update progress scope again once we've got rendered photo.
Expand Down Expand Up @@ -598,18 +598,18 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon
}
)

if didReplace then
-- The replace call used by StippleAPI.uploadPhoto ignores all of the metadata that is passed
-- in above. We have to manually upload that info after the fact in this case.
if exportSettings.titleRepublishBehavior == 'replace' then
--StippleAPI.callRestMethod( exportSettings, {
--method = 'stipple.photos.setMeta',
--photo_id = stipplePhotoId,
--title = title or '',
--description = description or '',
--})
end
end
-- if didReplace then
-- -- The replace call used by StippleAPI.uploadPhoto ignores all of the metadata that is passed
-- -- in above. We have to manually upload that info after the fact in this case.
-- if exportSettings.titleRepublishBehavior == 'replace' then
-- --StippleAPI.callRestMethod( exportSettings, {
-- --method = 'stipple.photos.setMeta',
-- --photo_id = stipplePhotoId,
-- --title = title or '',
-- --description = description or '',
-- --})
-- end
-- end

-- When done with photo, delete temp file. There is a cleanup step that happens later,
-- but this will help manage space in the event of a large upload.
Expand All @@ -623,13 +623,12 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon
if not isDefaultCollection then
-- Create or update this photoset.
photosetUrl = 'https://stipple.com'

--photosetId, photosetUrl = StippleAPI.createOrUpdatePhotoset(exportSettings, {
--photosetId = photosetId,
--title = publishedCollectionInfo.name,
--description = ??,
--primary_photo_id = uploadedPhotoIds[ 1 ],
--})
photosetId, photosetUrl = StippleAPI.createOrUpdatePhotoset(exportSettings, {
photosetId = photosetId,
name = publishedCollectionInfo.name,
description = '',
primary_photo_id = uploadedPhotoIds[ 1 ],
})
else
photosetUrl = StippleAPI.constructPhotostreamURL( exportSettings ) -- Photostream: find the URL.
end
Expand All @@ -646,10 +645,10 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon
})

-- Add the uploaded photos to the correct photoset.
-- StippleAPI.addPhotosToSet(exportSettings, {
-- photoId = stipplePhotoId,
-- photosetId = photosetId,
-- })
StippleAPI.addPhotosToSet(exportSettings, {
photoId = stipplePhotoId,
photosetId = photosetId,
})
else
photoUrl = StippleAPI.constructPhotoURL(exportSettings, {
id = stipplePhotoId,
Expand All @@ -673,7 +672,7 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon

if #uploadedPhotoIds > 0 then
if (not isDefaultCollection) then
--exportSession:recordRemoteCollectionId( photosetId )
exportSession:recordRemoteCollectionId( photosetId )
end

-- Set up some additional metadata for this collection.
Expand Down
23 changes: 19 additions & 4 deletions StipplePublishSupport.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
-- Lightroom SDK
local LrDialogs = import 'LrDialogs'
local LrApplication = import 'LrApplication'
local LrTasks = import 'LrTasks'
local catalog = LrApplication.activeCatalog()

-- Stipple plug-in
require 'StippleAPI'
Expand Down Expand Up @@ -503,10 +506,22 @@ end
-- @param localCollectionId (number) The local identifier for the collection for which
-- photos are being removed.

function publishServiceProvider.deletePhotosFromPublishedCollection( publishSettings, arrayOfPhotoIds, deletedCallback )
for i, photoId in ipairs( arrayOfPhotoIds ) do
StippleAPI.deletePhoto( publishSettings, { photoId = photoId, suppressErrorCodes = { [ 1 ] = true } } ) -- If Stipple says photo not found, ignore that.
deletedCallback( photoId )
function publishServiceProvider.deletePhotosFromPublishedCollection( publishSettings, arrayOfPhotoIds, deletedCallback, localId )
local set = {}

local function removePhotos(setId)
for i, photoId in ipairs( arrayOfPhotoIds ) do
StippleAPI.deletePhotoFromPhotoset( publishSettings, { photoId = photoId, photosetId = setId, suppressErrorCodes = { [ 1 ] = true } } ) -- If Stipple says photo not found, ignore that.
end
end

LrTasks.startAsyncTask(function()
set = catalog:getPublishedCollectionByLocalIdentifier(localId)
removePhotos(set:getRemoteId())
end)

for _,id in ipairs( arrayOfPhotoIds ) do
deletedCallback( id )
end
end

Expand Down
6 changes: 4 additions & 2 deletions StippleUser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ function StippleUser.login( propertyTable )

if propertyTable.LR_editingExistingPublishConnection then
if auth.user and propertyTable.nsid ~= auth.user.id then
LrDialogs.message( LOC "$$$/Stipple/CantChangeUserID=You can not change Stipple accounts on an existing publish connection. Please log in again with the account you used when you first created this connection." )
return
-- propertyTable.nsid = auth.user.id
-- LrDialogs.message( LOC "$$$/Stipple/CantChangeUserID=You can not change Stipple accounts on an existing publish connection. Please log in again with the account you used when you first created this connection." )
-- return
end
end

Expand Down Expand Up @@ -117,6 +118,7 @@ function StippleUser.verifyLogin(propertyTable)
propertyTable.validAccount = true
end
else
propertyTable.LR_editingExistingPublishConnection = true
notLoggedIn(propertyTable)
end

Expand Down

0 comments on commit 49398e5

Please sign in to comment.