-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGalleryUploadTask.lua
124 lines (98 loc) · 4.23 KB
/
GalleryUploadTask.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
--[[----------------------------------------------------------------------------
Implementation of the upload facilities to the remote Gallery.
Copyright (C) 2007-2009 Arnaud Mouronval <[email protected]>
Copyright (C) 2007 Moritz Post <[email protected]>
Released under the GNU GPL.
-----------------------------------------------------------------------------]]--
-- Lightroom API
local LrPathUtils = import 'LrPathUtils'
local LrFtp = import 'LrFtp'
local LrFileUtils = import 'LrFileUtils'
local LrErrors = import 'LrErrors'
local LrDialogs = import 'LrDialogs'
local LrHttp = import 'LrHttp'
local LrLogger = import 'LrLogger'
local prefs = import 'LrPrefs'.prefsForPlugin()
-- setup logger
local log = LrLogger( 'LR2Gallery' )
--============================================================================--
GalleryUploadTask = {}
--------------------------------------------------------------------------------
function GalleryUploadTask.processRenderedPhotos( functionContext, exportContext )
log:trace ("Calling GalleryUploadTask.processRenderedPhotos( functionContext, exportContext )")
-- Make a local reference to the export parameters.
local exportSession = exportContext.exportSession
local exportParams = exportContext.propertyTable
-- Set progress title.
local nPhotos = exportSession:countRenditions()
-- get server
serverId = exportParams.serverValue
-- get album
albumName = exportParams.albumValue
-- get metadata settings
captionSetting = exportParams.caption
local progressScope = exportContext:configureProgress{
title = nPhotos > 1
and LOC( "$$$/GalleryUpload/Upload/Progress=Uploading ^1 photos to the Gallery", nPhotos )
or LOC "$$$/GalleryUpload/Upload/Progress/One=Uploading one photo to the Gallery",
}
-- Iterate through photo renditions.
local failures = {}
for i, rendition in exportContext:renditions{ stopIfCanceled = true } do
-- Get next photo.
local photo = rendition.photo
local success, pathOrMessage = rendition:waitForRender()
-- Check for cancellation again after photo has been rendered.
if progressScope:isCanceled() then
break
end
if success then
local filename = LrPathUtils.leafName( pathOrMessage )
local caption = ''
-- Set the caption
if captionSetting == 'none' then
caption = ''
elseif captionSetting == 'filename' then
caption = filename
elseif captionSetting == 'title' then
photo.catalog:withCatalogDo( function()
caption = photo:getFormattedMetadata ( 'title' )
end )
elseif captionSetting == 'caption' then
photo.catalog:withCatalogDo( function()
caption = photo:getFormattedMetadata ( 'caption' )
end )
end
-- upload file to gallery
success = GalleryRemoteProtocol.uploadImage( serverId, albumName, pathOrMessage, caption )
if success ~= '0' then
-- if we can't upload that file, log it. For example, maybe user has exceeded disk
-- quota, or the file already exists and we don't have permission to overwrite, or
-- we don't have permission to write to that directory, etc....
table.insert( failures, filename )
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.
LrFileUtils.delete( pathOrMessage )
end
end
if #failures > 0 then
local message
if #failures == 1 then
message = LOC "$$$/GalleryUpload/Upload/Errors/OneFileFailed=A file failed to upload correctly."
else
message = LOC ( "$$$/GalleryUpload/Upload/Errors/SomeFileFailed=^1 files failed to upload correctly.", #failures )
end
LrDialogs.message( message, table.concat( failures, "\n" ) )
else
-- show album in browser if desired
if exportParams.showInBrowser == true then
local server = prefs.serverTable[serverId].server
if prefs.serverTable[serverId].version == '1' then
LrHttp.openUrlInBrowser( GalleryRemoteProtocol.getGalleryURL( server ).."view_album.php?set_albumName="..albumName )
else
LrHttp.openUrlInBrowser( GalleryRemoteProtocol.getGalleryURL( server ).."?g2_itemId="..albumName )
end
end
end
end