From fa85522e4feccc7cd61fe97a7aabb01640ead45d Mon Sep 17 00:00:00 2001 From: Sean Dick Date: Thu, 5 Dec 2013 15:57:06 -0800 Subject: [PATCH] fix dead credentials better. --- StippleAPI.lua | 29 +++++++++++++++++++++++++---- StippleExportServiceProvider.lua | 11 ++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/StippleAPI.lua b/StippleAPI.lua index 6839a86..179c76e 100644 --- a/StippleAPI.lua +++ b/StippleAPI.lua @@ -126,6 +126,11 @@ function StippleAPI.getApiKeyAndSecret() return apiKey end +function StippleAPI.resetApiKey() + prefs.apiKey = '' + StippleAPI.getApiKeyAndSecret() +end + -------------------------------------------------------------------------------- function StippleAPI.makeApiSignature( params ) @@ -211,7 +216,12 @@ function StippleAPI.getRestMethod( propertyTable, params ) -- Mac has different implementation with that on Windows when the server refuses the request. if hdrs.status ~= 200 then - LrErrors.throwUserError( formatError( hdrs.status ) ) + if hdrs.status == 401 then + StippleAPI.resetApiKey() + + else + LrErrors.throwUserError( formatError( hdrs.status ) ) + end end appearsAlive = true @@ -350,6 +360,17 @@ function StippleAPI.uploadPhoto( propertyTable, params ) tostring( json.status ))) end end +-------------------------------------------------------------------------------- + +function StippleAPI.getSetPhotos( propertyTable, params ) + local response = StippleAPI.getRestMethod( nil, { url = params.url or 'sets/' .. params.setId }) + if response.data and response.data.set and response.data.set.photos and #response.data.set.photos < 1 then + return + end + for _,photo in pairs(response.data.set.photos) do + tryAddPhoto(photo) + end +end -------------------------------------------------------------------------------- @@ -406,12 +427,12 @@ end -------------------------------------------------------------------------------- function StippleAPI.listPhotosFromPhotoset( propertyTable, params ) - local response, ids = {}, {} + local response, photos = {}, {} response = StippleAPI.getRestMethod(nil, {url = 'sets/' .. params.photosetId}) for _,photo in pairs(response.data.set.photos) do - table.insert(ids,photo.id) + table.insert(photos,photo) end - return ids + return photos end -------------------------------------------------------------------------------- diff --git a/StippleExportServiceProvider.lua b/StippleExportServiceProvider.lua index bc7fd07..f1292cd 100644 --- a/StippleExportServiceProvider.lua +++ b/StippleExportServiceProvider.lua @@ -535,15 +535,10 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon -- Get a list of photos already in this photoset so we know which ones we can replace and which have -- to be re-uploaded entirely. - local photosetPhotoIds = photosetId and StippleAPI.listPhotosFromPhotoset( exportSettings, { photosetId = photosetId } ) + local photosetPhotos = photosetId and StippleAPI.listPhotosFromPhotoset( exportSettings, { photosetId = photosetId } ) local photosetPhotosSet = {} -- Turn it into a set for quicker access later. - if photosetPhotoIds then - for _, id in ipairs( photosetPhotoIds ) do - photosetPhotosSet[ id ] = true - end - end local couldNotPublishBecauseFreeAccount = {} local stipplePhotoIdsForRenditions = {} @@ -593,7 +588,9 @@ function exportServiceProvider.processRenderedPhotos( functionContext, exportCon id = stipplePhotoId, filePath = pathOrMessage, photo = { - caption = description, source_page = "Stipple Lightroom Plugin" }, + caption = description, + source_page = "" + }, claim = 1, -- always claim the photo } )