flingo64 / PhotoStation-Upload-Lr-Plugin

Photo StatLr (aka PhotoStation Upload) is a Lightroom Publish and Export Service Plugin that enables the export /publishing of photos and videos from Lr to a Synology Photo Station. It uploads the photos/videos and all required thumbnails. It can download comments and ratings and do a real two-way synch of various metadata (tags, ratings, labels).
http://messmer-online.de/index.php/software/11-photo-statlr
GNU General Public License v3.0
209 stars 21 forks source link

Internal error: invalid JSON data / JSON Decode error #52

Closed HendriXML closed 3 years ago

HendriXML commented 3 years ago

After updating the plugin from 6.8.5 to 6.9.5 I get multiple popups with this error Internal error: invalid JSON data in ...

The log then mentions: ERROR: JSON-DecodeError('checkPSUploadAPIAnswer(PSUploadAPI.uploadPictureFile('C:\Users\Me\AppData\Local\Temp\01C6DC2E-7183-4AB1-A3C0-C5ACA0727591[2008-01-23 25 24 12] PICT0003.jpg', 'Dag', '[2008-01-23 25 24 12] PICT0003.jpg'))')trailing garbage at character 2

Having brackets [] in the filename was mentioned as a possible issue previously (issue: #36) as it's part of the regular expression grammar. (If that's the case there's probably a way to escape those characters.)

I hope this can be solved because all my pictures/video's have a [yyyy-mm-dd] prefix in their filenames.

HendriXML commented 3 years ago

I went back to version 6.8.5, but then the same dialog pops up, so it may happen only when republishing/updating a collection.

flingo64 commented 3 years ago

Couldn't believe it only happens after a second upload, but you are right: works good the first time, fails the second time.

If you do the Publish wth Loglevel Debug and check the logfile after the exception, you will see the reason: the Upload API of the Photo Station obviously isn't able to handle filenames like that (including square brackets). It is complaining that it can't rename a temporary dir to the target dir since it isn't empty. Instead of returning a JSON formatted response it returns a plain-text error message, which breaks the JSON decode.

Since this is an issue in the Photo Station Upload API, I can't do anything about it. I suggest to use the renaming functionality of the Plugin to generate feasible remote filenames.

HendriXML commented 3 years ago

Thanks for clarifying the issue, I'll take a look at the debug log as well.

It's good to know there's a work around, though! (I hope it doesn't affect matching files on updating meta data)

I'm using your plugin for years (but not very frequent), as well as my naming convention. There used to be a time that updating a collection worked as expected. So my guess is that the upload tool's behavior has changed in some update of it.

HendriXML commented 3 years ago

I went back to version 1.3-080 of the uploader, which has the same issue, so going back is not a solution.

I couldn't find the option to set the debug level in the published smart collection dialog. (I could find it in the exporting dialog)

flingo64 commented 3 years ago

I went back to version 1.3-080 of the uploader, which has the same issue, so going back is not a solution.

It's not the client side code, it's the server side code, so you would have to downgrade the Photo Station....

I couldn't find the option to set the debug level in the published smart collection dialog. (I could find it in the exporting dialog)

It's in the Publish Service settings

flingo64 commented 3 years ago

It's good to know there's a work around, though! (I hope it doesn't affect matching files on updating meta data)

The issue is only in the Upload API, all other Publish Modes should work fine.

HendriXML commented 3 years ago

After setting the debug loglevel it shows even the linenr of the php-page that throws the exception. That's nice, I'll take a look at it later on and maybe it can be fixed easily. It seems like its treating the photo filename as a directory as well. (Must say php is not my cup of tea.) On the clientside it might be bypassed by turning an "update" into a "delete, add new" action.

flingo64 commented 3 years ago

The Upload generates a folder under the respective hidden @eaDir folder holding the thumbs. This folder has the same name as the belonging photo file.

HendriXML commented 3 years ago

I edited the file "asst_file_upload.php" to have the brackets properly escaped. That seems to do the trick. on line 204 replaced $files = glob($dest_ea_folder_path.'/', GLOB_MARK ); with $files = glob(str_replace("]", "\]", str_replace("[", "\[", $dest_ea_folder_path)).'/', GLOB_MARK );

flingo64 commented 3 years ago

Excellent! Should we make an Q&A for this issue?

HendriXML commented 3 years ago

Possibly, but I guess for some users it might be tricky to edit the file. I used vi with root access, but that requires a bit of setup.

Anyway thanks for pointing into the right direction!

flingo64 commented 3 years ago

Added a short Q&A on the issue

HendriXML commented 3 years ago

Just a side note: Brachets are not special on OS level. Only in the high level php function call to get a list of files for a directory. They should have taken a less fancy function with no wildcard/alternatives functionality. (Or some escaping). Such fancy stuff can be subject to "injecting logic". Comparable to SQL injection. For instance this bug might be used to clear directories on wrong locations. (Haven't looked into what those brackets should do, though)

22 apr. 2021 21:46:10 Martin @.***>:

Added a short Q&A on the issue[https://github.com/flingo64/PhotoStation-Upload-Lr-Plugin/blob/master/Documentation/23-Internal_error-invalid_JSON_data-JSON_Decode_error_when_uploading_photos_w_square_brackets_in_filename.md]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[https://github.com/flingo64/PhotoStation-Upload-Lr-Plugin/issues/52#issuecomment-825137221], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AJTSUMWMM5FF754WKNZZ5EDTKB4IFANCNFSM42RKS7PA]. [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAtCAYAAAA6GuKaAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAAfSURBVFiF7cExAQAAAMKg9U9tDQ+gAAAAAAAAAIA7Ax/RAAHhikzQAAAAAElFTkSuQmCC###24x24:true###][Tracking afbeelding][https://github.com/notifications/beacon/AJTSUMWCVKD4GETZHYBEV4TTKB4IFA5CNFSM42RKS7PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGEXJQRI.gif]