Skip to content

Commit 31a55bf

Browse files
committed
Anonymise log data and add additional debug code in renderphotos
1 parent 320e09f commit 31a55bf

5 files changed

Lines changed: 80 additions & 24 deletions

File tree

piwigoPublish.lrplugin/PWSetAlbumCover.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ local function SetAlbumCover()
8989
local thisPubPhoto = utils.findPhotoInCollectionSet(useSource, selPhoto)
9090
if not thisPubPhoto then
9191
LrDialogs.message(
92-
"PiwigoAPI.setAlbumCover - Can't find this photo in collection set or collections - has it been published?", "",
92+
"PWSetAlbumCover - Can't find this photo in collection set or collections - has it been published?", "",
9393
"warning")
9494
return false
9595
end
9696
local remoteId = thisPubPhoto:getRemoteId()
9797
if not remoteId or remoteId == "" then
98-
LrDialogs.message("PiwigoAPI.setAlbumCover - Can't find Piwigo photo ID for this photo - has it been published?", "", "warning")
98+
LrDialogs.message("PWSetAlbumCover - Can't find Piwigo photo ID for this photo - has it been published?", "", "warning")
9999
return false
100100
end
101101

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,15 +2523,15 @@ function PiwigoAPI.deletePhoto(propertyTable, pwCatID, pwImageID, callStatus)
25232523
callStatus.status = true
25242524
callStatus.statusMsg = ""
25252525
else
2526-
log:info("PiwigoAPI.deletePhoto - propertyTable \n " .. utils.serialiseVar(propertyTable))
2526+
log:info("PiwigoAPI.deletePhoto - propertyTable \n " .. utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)))
25272527
log:info("PiwigoAPI.deletePhoto - params \n" .. utils.serialiseVar(params))
25282528
log:info("PiwigoAPI.deletePhoto - httpResponse \n" .. utils.serialiseVar(httpResponse))
25292529
log:info("PiwigoAPI.deletePhoto - httpHeaders \n" .. utils.serialiseVar(httpHeaders))
25302530
callStatus.status = false
25312531
callStatus.statusMsg = body.message or ""
25322532
end
25332533
else
2534-
log:info("PiwigoAPI.deletePhoto - propertyTable \n " .. utils.serialiseVar(propertyTable))
2534+
log:info("PiwigoAPI.deletePhoto - propertyTable \n " .. utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)))
25352535
log:info("PiwigoAPI.deletePhoto - params \n" .. utils.serialiseVar(params))
25362536
log:info("PiwigoAPI.deletePhoto - httpResponse \n" .. utils.serialiseVar(httpResponse))
25372537
log:info("PiwigoAPI.deletePhoto - httpHeaders \n" .. utils.serialiseVar(httpHeaders))
@@ -2635,7 +2635,7 @@ function PiwigoAPI.addComment(publishSettings, metaData)
26352635
-- get antispam token from image details (unique for each image)
26362636
local rtnStatus = PiwigoAPI.checkPhoto(publishSettings, metaData.remoteId)
26372637
if not rtnStatus.status then
2638-
log:info("PiwigoAPI.addComment - unanble to retrieve token\n" .. utils.serialiseVar(publishSettings))
2638+
log:info("PiwigoAPI.addComment - unanble to retrieve token\n" .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
26392639
return false
26402640
end
26412641
local imageDets = rtnStatus.imageDets
@@ -2658,11 +2658,11 @@ function PiwigoAPI.addComment(publishSettings, metaData)
26582658
return false
26592659
end
26602660
if utils.nilOrEmpty(author) then
2661-
log:info("PiwigoAPI.addComment - missing author\n" .. utils.serialiseVar(publishSettings))
2661+
log:info("PiwigoAPI.addComment - missing author\n" .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
26622662
return false
26632663
end
26642664
if utils.nilOrEmpty(key) then
2665-
log:info("PiwigoAPI.addComment - missing key\n" .. utils.serialiseVar(publishSettings))
2665+
log:info("PiwigoAPI.addComment - missing key\n" .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
26662666
return false
26672667
end
26682668
-- Piwigo antispam forces a delay between the key being created and used
@@ -2759,7 +2759,7 @@ function PiwigoAPI.setAlbumCover(publishService)
27592759
log:info("publishservice" .. publishService:getName())
27602760
local catalog = LrApplication.activeCatalog()
27612761
local publishSettings = publishService:getPublishSettings()
2762-
log:info("publishSettings\n" .. utils.serialiseVar(publishSettings))
2762+
log:info("publishSettings\n" .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
27632763

27642764
if not publishSettings then
27652765
LrDialogs.message("PiwigoAPI.setAlbumCover - Can't find PublishSettings for this publish collection", "",

piwigoPublish.lrplugin/PublishServiceProvider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ return {
4040

4141
-- Piwigo supports .jpg, .jpeg, .png, .gif, .webp, .heic
4242
-- of these, LrC can only export JPEG and PNG, so we limit to those formats in the publish dialog.
43-
allowFileFormats = { "JPEG", "PNG"},
43+
allowFileFormats = { "JPEG", "PNG", "TIFF"},
4444

4545
allowColorSpaces = nil,
4646
canExportVideo = false,

piwigoPublish.lrplugin/PublishTask.lua

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
3838
local publishService = publishedCollection:getService()
3939
local rv
4040
if not publishService then
41-
log:info('PublishTask.processRenderedPhotos - publishSettings:\n' .. utils.serialiseVar(propertyTable))
41+
log:info('PublishTask.processRenderedPhotos - propertyTable:\n' ..
42+
utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)))
4243
LrErrors.throwUserError('Publish photos to Piwigo - cannot connect find publishService')
4344
return nil
4445
end
@@ -77,7 +78,8 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
7778
if not (propertyTable.Connected) then
7879
rv = PiwigoAPI.login(propertyTable)
7980
if not rv then
80-
log:info('PublishTask.processRenderedPhotos - publishSettings:\n' .. utils.serialiseVar(propertyTable))
81+
log:info('PublishTask.processRenderedPhotos - propertyTable:\n' ..
82+
utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)))
8183
PWStatusManager.setPiwigoBusy(publishService, false)
8284
LrErrors.throwUserError('Publish photos to Piwigo - cannot connect to piwigo at ' .. propertyTable.host)
8385
return nil
@@ -264,8 +266,6 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
264266
end
265267

266268
-- store / update custom metadata
267-
268-
269269
PiwigoAPI.storeMetaData(catalog, lrPhoto, pluginData)
270270

271271
-- photo was uploaded with keywords included, but existing keywords aren't replaced by this process,
@@ -285,13 +285,36 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
285285
LrDialogs.message("Unable to set metadata for uploaded photo - " .. callStatus.statusMsg)
286286
end
287287
else
288-
log:info("Upload failed for photo " .. lrPhoto:getFormattedMetadata("fileName"))
289-
log:info("Upload failed - renditionSettings\n" .. utils.serialiseVar(renditionParams))
290-
log:info("Upload failed - metaData\n" .. utils.serialiseVar(metaData))
291-
log:info("Upload failed - propertyTable\n" .. utils.serialiseVar(propertyTable))
288+
local sourcePhotoName = lrPhoto:getFormattedMetadata("fileName")
289+
local anonymiseRenditionParams = utils.anonymiseRenditionParams(renditionParams)
290+
local expRenditionParams = utils.serialiseVar(anonymiseRenditionParams)
291+
local expMetaData = utils.serialiseVar(metaData)
292+
log:info("Upload failed for photo: " .. sourcePhotoName)
293+
log:info("Upload failed - renditionParams\n" .. expRenditionParams)
294+
log:info("Upload failed - metaData\n" .. expMetaData)
295+
log:info("Upload failed - propertyTable\n" .. utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)))
292296
log:info("Upload failed - callStatus\n" .. utils.serialiseVar(callStatus))
293297
log:info("Upload failed - pathOrMessage\n" .. tostring(pathOrMessage))
294298

299+
local debugDir = LrPathUtils.child(LrPathUtils.getStandardFilePath('desktop'),
300+
"PiwigoPublishDebugIssue17")
301+
LrFileUtils.createAllDirectories(debugDir)
302+
local leafName = LrPathUtils.leafName(pathOrMessage)
303+
local debugPath = LrPathUtils.child(debugDir, leafName)
304+
LrFileUtils.copy(pathOrMessage, debugPath)
305+
306+
local debugFileName = debugPath .. "_debug.txt"
307+
local debugFile = io.open(debugFileName, "w")
308+
debugFile:write("Upload failed for photo: " .. sourcePhotoName .. "\n")
309+
debugFile:write("Rendition params:\n" .. expRenditionParams .. "\n")
310+
debugFile:write("Metadata:\n" .. expMetaData .. "\n")
311+
debugFile:write("PropertyTable:\n" .. utils.serialiseVar(utils.anonymisePropertyTable(propertyTable)) .. "\n")
312+
debugFile:write("CallStatus:\n" .. utils.serialiseVar(callStatus) .. "\n")
313+
debugFile:write("PathOrMessage:\n" .. tostring(pathOrMessage) .. "\n")
314+
debugFile:close()
315+
316+
log:warn("DEBUG: preserved failed upload file to " .. debugPath)
317+
295318
rendition:uploadFailed(callStatus.message or "Upload failed")
296319
end
297320

@@ -377,7 +400,7 @@ function PublishTask.deletePhotosFromPublishedCollection(publishSettings, arrayO
377400
local publishedPhotos = publishedCollection:getPublishedPhotos()
378401
local publishService = publishedCollection:getService()
379402
if not publishService then
380-
log:info('deletePhotosFromPublishedCollection - publishSettings:\n' .. utils.serialiseVar(publishSettings))
403+
log:info('deletePhotosFromPublishedCollection - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
381404
LrErrors.throwUserError('Publish photos to Piwigo - cannot connect find publishService')
382405
return nil
383406
end
@@ -494,7 +517,7 @@ function PublishTask.getCommentsFromPublishedCollection(publishSettings, arrayOf
494517
local rv, publishService = PiwigoAPI.getPublishService(publishSettings)
495518
if not (publishService) or not (rv) then
496519
log:info('PublishTask.getCommentsFromPublishedCollection - publishSettings:\n' ..
497-
utils.serialiseVar(publishSettings))
520+
utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
498521
LrErrors.throwUserError('PublishTask.getCommentsFromPublishedCollection - cannot find publishService')
499522
return nil
500523
end
@@ -956,7 +979,7 @@ function PublishTask.updateCollectionSettings(publishSettings, info)
956979

957980

958981
if not publishService then
959-
log:info('updateCollectionSettings - publishSettings:\n' .. utils.serialiseVar(publishSettings))
982+
log:info('updateCollectionSettings - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
960983
LrErrors.throwUserError('updateCollectionSettings - cannot connect find publishService')
961984
return nil
962985
end
@@ -1167,7 +1190,7 @@ function PublishTask.updateCollectionSetSettings(publishSettings, info)
11671190
local publishService = info.publishService
11681191

11691192
if not publishService then
1170-
log:info('updateCollectionSettings - publishSettings:\n' .. utils.serialiseVar(publishSettings))
1193+
log:info('updateCollectionSettings - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
11711194
LrErrors.throwUserError('updateCollectionSettings - cannot connect find publishService')
11721195
return nil
11731196
end
@@ -1264,7 +1287,7 @@ function PublishTask.reparentPublishedCollection(publishSettings, info)
12641287

12651288
local publishService = info.publishService
12661289
if not publishService then
1267-
log:info('reparentPublishedCollection - publishSettings:\n' .. utils.serialiseVar(publishSettings))
1290+
log:info('reparentPublishedCollection - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
12681291
LrErrors.throwUserError('reparentPublishedCollection - cannot connect find publishService')
12691292
return nil
12701293
end
@@ -1316,7 +1339,7 @@ function PublishTask.renamePublishedCollection(publishSettings, info)
13161339
-- called for both collections and collectionsets
13171340
local publishService = info.publishService
13181341
if not publishService then
1319-
log:info('renamePublishedCollection - publishSettings:\n' .. utils.serialiseVar(publishSettings))
1342+
log:info('renamePublishedCollection - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
13201343
LrErrors.throwUserError('renamePublishedCollection - cannot connect find publishService')
13211344
return nil
13221345
end
@@ -1398,7 +1421,7 @@ function PublishTask.deletePublishedCollection(publishSettings, info)
13981421
local publishService = info.publishService
13991422
local publishCollection = info.publishedCollection
14001423
if not publishService then
1401-
log:info('deletePublishedCollection - publishSettings:\n' .. utils.serialiseVar(publishSettings))
1424+
log:info('deletePublishedCollection - publishSettings:\n' .. utils.serialiseVar(utils.anonymisePropertyTable(publishSettings)))
14021425
LrErrors.throwUserError('deletePublishedCollection - cannot connect find publishService')
14031426
return nil
14041427
end

piwigoPublish.lrplugin/utils.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@
2222

2323

2424
local utils = {}
25+
-- *************************************************
26+
function utils.anonymisePropertyTable(propertyTable)
27+
-- return copy of property table with sensitive data removed (for logging etc)
28+
local ptCopy = propertyTable
29+
ptCopy.userPW = "****"
30+
ptCopy.userName = "****"
31+
ptCopy.host = "****"
32+
ptCopy.pwurl = "****"
33+
ptCopy.cookieHeader = "****"
34+
ptCopy.SessionCookie = "**** "
35+
ptCopy.token = "****"
36+
ptCopy.cookies = "****"
37+
ptCopy.tagTable = nil
38+
ptCopy._tagIndex = nil
39+
return ptCopy
40+
end
41+
42+
-- *************************************************
43+
function utils.anonymiseRenditionParams(renditionParams)
44+
-- return copy of renditionParams with sensitive data removed (for logging etc)
45+
local rpCopy = renditionParams
46+
rpCopy.exportContext.propertyTable.userPW = "****"
47+
rpCopy.exportContext.propertyTable.userName = "****"
48+
rpCopy.exportContext.propertyTable.host = "****"
49+
rpCopy.exportContext.propertyTable.pwurl = "****"
50+
rpCopy.exportContext.propertyTable.cookieHeader = "****"
51+
rpCopy.exportContext.propertyTable.SessionCookie = "**** "
52+
rpCopy.exportContext.propertyTable.token = "****"
53+
rpCopy.exportContext.propertyTable.cookies = "****"
54+
rpCopy.exportContext.propertyTable.tagTable = nil
55+
rpCopy.exportContext.propertyTable._tagIndex = nil
56+
return rpCopy
57+
end
2558

2659
-- *************************************************
2760
function utils.stripHtml(s)

0 commit comments

Comments
 (0)