Skip to content

Commit

Permalink
Some more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmachek committed Aug 29, 2024
1 parent 11c87e8 commit 4ea4721
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion immich-plugin.lrdevplugin/ExportTask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ExportTask = {}

function ExportTask.processRenderedPhotos(functionContext, exportContext)
if not immich:checkConnectivity() then
LrDialogs.error('Immich connection not set up.')
LrDialogs.showError('Immich connection not set up.')
return nil
end
-- Make a local reference to the export parameters.
Expand Down
32 changes: 23 additions & 9 deletions immich-plugin.lrdevplugin/ImmichAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ ImmichAPI.__index = ImmichAPI

function ImmichAPI:new(url, apiKey)
local o = setmetatable({}, ImmichAPI)
self.apiKey = apiKey
self.deviceIdString = 'Lightroom Immich Upload Plugin'
self.apiBasePath = '/api'
self.apiKey = apiKey
self.url = url
return o
end

function ImmichAPI:reconfigure(url, apiKey)
self.apiKey = apiKey
self.url = url
log:trace('Immich reconfigured with ' .. self.url)
end

local function generateMultiPartBody(b, formData, filePath)

local fileName = LrPathUtils.leafName(filePath)
Expand Down Expand Up @@ -97,8 +103,13 @@ end

function ImmichAPI:checkConnectivity()
log:trace('checkConnectivity: Sending getMyUser request')

log:trace('ImmichAPI: Preparing GET request /users/me')

if util.nilOrEmpty(self.url) or util.nilOrEmpty(self.apiKey) then
log:error('checkConnectivity: test failed.')
return false
end

local response, headers = LrHttp.get(self.url .. self.apiBasePath .. '/users/me', ImmichAPI:createHeaders())

if headers.status == 200 then
Expand Down Expand Up @@ -500,12 +511,15 @@ function ImmichAPI:doMultiPartPutRequest(apiPath, filePath, formData)
end
end


function ImmichAPI.immichConnected()
if immich == nil then
return false
elseif immich:checkConnectivity() then
return true
else
return false
end
end

-- Global instance of connection to immich.
_G.immich = nil
_G.immichConfigured = false
if not util.nilOrEmpty(prefs.url) and not util.nilOrEmpty(prefs.apiKey) then
_G.immich = ImmichAPI:new(prefs.url, prefs.apiKey)
_G.immichConfigured = true
end
_G.immich = ImmichAPI:new(prefs.url, prefs.apiKey)
10 changes: 4 additions & 6 deletions immich-plugin.lrdevplugin/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ _G.log = import 'LrLogger'('ImmichPlugin')
if _G.prefs.logging == nil then
_G.prefs.logging = false
end
if _G.prefs.logging then
_G.log:enable('logfile')
else
_G.log:disable()
end

if _G.prefs.logging then _G.log:enable('logfile')
else _G.log:disable() end

if _G.prefs.apiKey == nil then _G.prefs.apiKey = '' end
if _G.prefs.url == nil then _G.prefs.url = '' end
3 changes: 3 additions & 0 deletions immich-plugin.lrdevplugin/PluginInfoDialogSections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ end
function PluginInfoDialogSections.endDialog(propertyTable)
prefs.apiKey = propertyTable.apiKey
prefs.url = propertyTable.url

immich:reconfigure(prefs.url, prefs.apiKey)

prefs.logging = propertyTable.logging
if propertyTable.logging then
log:enable('logfile')
Expand Down
6 changes: 3 additions & 3 deletions immich-plugin.lrdevplugin/PublishServiceProvider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ return {

-- shouldRenderPhoto = true, -- Sufficient???

startDialog = PublishDialogSections.startDialog,
-- startDialog = PublishDialogSections.startDialog,
-- sectionsForTopOfDialog = PublishDialogSections.sectionsForTopOfDialog,


Expand All @@ -26,11 +26,11 @@ return {
-- getCommentsFromPublishedCollection = PublishTask.getCommentsFromPublishedCollection,

deletePhotosFromPublishedCollection = PublishTask.deletePhotosFromPublishedCollection,
reparentPublishedCollection = function (publishSettings, info) end,
reparentPublishedCollection = PublishTask.reparentPublishedCollection,
deletePublishedCollection = PublishTask.deletePublishedCollection,
renamePublishedCollection = PublishTask.renamePublishedCollection,
shouldDeletePhotosFromServiceOnDeleteFromCatalog = PublishTask.shouldDeletePhotosFromServiceOnDeleteFromCatalog,
validatePublishedCollectionName = function (newName) return true, "" end,
validatePublishedCollectionName = PublishTask.validatePublishedCollectionName,


}
Expand Down
19 changes: 12 additions & 7 deletions immich-plugin.lrdevplugin/PublishTask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require "ImmichAPI"
PublishTask = {}

function PublishTask.processRenderedPhotos(functionContext, exportContext)
if not immich:checkConnectivity() then
LrDialogs.error('Immich connection not set up.')
if not ImmichAPI.immichConnected() then
LrDialogs.showError('Immich connection not set up.')
return nil
end

Expand Down Expand Up @@ -63,10 +63,8 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
atLeastSomeSuccess = true
rendition:recordPublishedPhotoId(id)
rendition:recordPublishedPhotoUrl(immich:getAssetUrl(id))
-- MetadataTask.setImmichAssetId(rendition.photo, id)

if util.table_contains(albumAssetIds, id) == false then
log:trace('Adding asset to album')
immich:addAssetToAlbum(albumId, id)
end
end
Expand Down Expand Up @@ -114,7 +112,7 @@ end

function PublishTask.deletePhotosFromPublishedCollection(publishSettings, arrayOfPhotoIds, deletedCallback, localCollectionId)
if not immich:checkConnectivity() then
LrDialogs.error('Immich connection not set up.')
LrDialogs.showError('Immich connection not set up.')
return nil
end
local catalog = LrApplication.activeCatalog()
Expand All @@ -130,15 +128,15 @@ end

function PublishTask.deletePublishedCollection(publishSettings, info)
if not immich:checkConnectivity() then
LrDialogs.error('Immich connection not set up.')
LrDialogs.showError('Immich connection not set up.')
return nil
end
ImmichAPI:deleteAlbum(info.remoteId)
end

function PublishTask.renamePublishedCollection(publishSettings, info)
if not immich:checkConnectivity() then
LrDialogs.error('Immich connection not set up.')
LrDialogs.showError('Immich connection not set up.')
return nil
end
ImmichAPI:renameAlbum(info.remoteId, info.name)
Expand All @@ -149,3 +147,10 @@ function PublishTask.shouldDeletePhotosFromServiceOnDeleteFromCatalog(publishSet
return "ignore" -- Photos deleted locally are NOT deleted on Immich
-- This should open a dialog leaving the choice to the user.
end

function PublishTask.validatePublishedCollectionName(name)
return true, '' -- TODO
end

function PublishTask.reparentPublishedCollection(publishSettings, info)
end

0 comments on commit 4ea4721

Please sign in to comment.