Skip to content

Commit 69d3d6b

Browse files
committed
Add Album summary and Piwigo Server information
1 parent b6a4d3b commit 69d3d6b

3 files changed

Lines changed: 742 additions & 5 deletions

File tree

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,16 +1431,37 @@ function PiwigoAPI.getInfos(propertyTable)
14311431
end
14321432
local getResponse = httpGet(propertyTable.pwurl, Params, headers)
14331433
if getResponse.errorMessage or (not getResponse.response) then
1434-
LrDialogs.message("Cannot get user status from Piwigo - " .. (getResponse.errorMessage or "Unknown error"))
1434+
log:info("PiwigoAPI.getInfos - Params\n" .. utils.serialiseVar(Params))
1435+
log:info("PiwigoAPI.getInfos - headers\n" .. utils.serialiseVar(headers))
1436+
log:info("PiwigoAPI.getInfos - getResponse\n" .. utils.serialiseVar(getResponse))
1437+
LrDialogs.message("PiwigoAPI.getInfos - Cannot get host information from Piwigo - " ..
1438+
(getResponse.errorMessage or "Unknown error"))
14351439
return false
14361440
end
1437-
if getResponse.stat == "ok" then
1441+
1442+
if getResponse.status == "ok" then
14381443
rtnStatus.status = true
1439-
rtnStatus.result = getResponse.result.infos
1444+
local apiResult = getResponse.response.result
1445+
-- pwg.getInfos returns a PwgNamedArray: {infos: [{name, value}, ...]}
1446+
-- Try both structures
1447+
if type(apiResult) == "table" then
1448+
if apiResult.infos then
1449+
rtnStatus.result = apiResult.infos
1450+
elseif #apiResult > 0 then
1451+
rtnStatus.result = apiResult
1452+
else
1453+
rtnStatus.result = apiResult
1454+
end
1455+
end
14401456
else
1441-
rtnStatus.message = "Cannot get host information from Piwigo - " ..
1442-
((getResponse.stat .. " - Error" .. getResponse.err .. "- " .. getResponse.errorMessage) or "Unknown error")
1457+
log:info("PiwigoAPI.getInfos - Params\n" .. utils.serialiseVar(Params))
1458+
log:info("PiwigoAPI.getInfos - headers\n" .. utils.serialiseVar(headers))
1459+
log:info("PiwigoAPI.getInfos - getResponse\n" .. utils.serialiseVar(getResponse))
1460+
rtnStatus.message = "Cannot get host information from Piwigo - " ..
1461+
((getResponse.status .. " - " .. (getResponse.errorMessage or "Unknown error")) or "Unknown error")
14431462
end
1463+
1464+
14441465
return rtnStatus
14451466
end
14461467

@@ -3067,5 +3088,117 @@ function PiwigoAPI.createHeadersForMultipartPut(propertyTable, boundary, length)
30673088
} }
30683089
end
30693090

3091+
-- *************************************************
3092+
function PiwigoAPI.getServerVideoSupport(propertyTable)
3093+
-- Check server capabilities for video support
3094+
-- Returns { status, piwigoVersion, videoJsInstalled, videoJsActive, serverInfos }
3095+
log:info("PiwigoAPI.getServerVideoSupport")
3096+
local result = {
3097+
status = false,
3098+
piwigoVersion = propertyTable.pwVersion or "unknown",
3099+
videoJsInstalled = false,
3100+
videoJsActive = false,
3101+
serverInfos = {},
3102+
}
3103+
3104+
-- 1. Get server infos (photo/album counts etc.)
3105+
local infosResult = PiwigoAPI.getInfos(propertyTable)
3106+
if infosResult.status and infosResult.result then
3107+
-- pwg.getInfos returns a named array of {name, value} items
3108+
for _, item in ipairs(infosResult.result) do
3109+
if item.name and item.value then
3110+
result.serverInfos[item.name] = item.value
3111+
end
3112+
end
3113+
end
3114+
3115+
-- 2. Check for VideoJS plugin via pwg.plugins.getList
3116+
local pluginParams = { {
3117+
name = "method",
3118+
value = "pwg.plugins.getList"
3119+
} }
3120+
local headers = {}
3121+
if propertyTable.cookieHeader ~= nil then
3122+
headers = {
3123+
["Cookie"] = propertyTable.cookieHeader
3124+
}
3125+
end
3126+
local getResponse = httpGet(propertyTable.pwurl, pluginParams, headers)
3127+
if getResponse.status == "ok" and getResponse.response and getResponse.response.result then
3128+
-- pwg.plugins.getList may return plugins under .plugins key or directly as result
3129+
local responseResult = getResponse.response.result
3130+
log:info("PiwigoAPI.getServerVideoSupport - plugin list response keys: " ..
3131+
utils.serialiseVar(responseResult))
3132+
3133+
-- Try to find the plugins array in various possible structures
3134+
local plugins = nil
3135+
if type(responseResult) == "table" then
3136+
if responseResult.plugins and type(responseResult.plugins) == "table" then
3137+
plugins = responseResult.plugins
3138+
elseif #responseResult > 0 then
3139+
-- result is directly an array of plugins
3140+
plugins = responseResult
3141+
end
3142+
end
3143+
3144+
if plugins then
3145+
for _, plugin in ipairs(plugins) do
3146+
if type(plugin) == "table" then
3147+
local pluginId = tostring(plugin.id or "")
3148+
local pluginName = tostring(plugin.name or "")
3149+
-- Match on id or name, covering "piwigo-videojs", "videojs", "VideoJS", etc.
3150+
local idLower = pluginId:lower()
3151+
local nameLower = pluginName:lower()
3152+
if idLower:find("videojs") or idLower:find("video_js")
3153+
or nameLower:find("videojs") or nameLower:find("video_js") then
3154+
result.videoJsInstalled = true
3155+
local state = plugin.state and tostring(plugin.state) or "unknown"
3156+
result.videoJsActive = (state == "active")
3157+
result.videoJsName = plugin.name or pluginId
3158+
log:info("PiwigoAPI.getServerVideoSupport - VideoJS plugin found: id=" ..
3159+
pluginId .. " name=" .. pluginName .. " state=" .. state)
3160+
break
3161+
end
3162+
end
3163+
end
3164+
if not result.videoJsInstalled then
3165+
log:info("PiwigoAPI.getServerVideoSupport - scanned " .. #plugins ..
3166+
" plugins, VideoJS not found")
3167+
end
3168+
else
3169+
log:info("PiwigoAPI.getServerVideoSupport - unexpected plugin list structure")
3170+
end
3171+
else
3172+
log:info("PiwigoAPI.getServerVideoSupport - cannot retrieve plugin list: " ..
3173+
(getResponse.errorMessage or "unknown error"))
3174+
end
3175+
3176+
-- 3. Get detailed server config via pwg.companion.getConfig (PiwigoPublish Companion plugin)
3177+
result.serverConfig = nil
3178+
result.companionAvailable = false
3179+
local configParams = { {
3180+
name = "method",
3181+
value = "pwg.companion.getConfig"
3182+
} }
3183+
local cfgHeaders = {}
3184+
if propertyTable.cookieHeader ~= nil then
3185+
cfgHeaders = {
3186+
["Cookie"] = propertyTable.cookieHeader
3187+
}
3188+
end
3189+
local cfgResponse = httpGet(propertyTable.pwurl, configParams, cfgHeaders)
3190+
if cfgResponse.status == "ok" and cfgResponse.response and cfgResponse.response.result then
3191+
result.serverConfig = cfgResponse.response.result
3192+
result.companionAvailable = true
3193+
log:info("PiwigoAPI.getServerVideoSupport - companion plugin detected, config retrieved")
3194+
else
3195+
log:info("PiwigoAPI.getServerVideoSupport - serverinfo plugin not available: " ..
3196+
(cfgResponse.errorMessage or "unknown error"))
3197+
end
3198+
3199+
result.status = true
3200+
return result
3201+
end
3202+
30703203
-- *************************************************
30713204
return PiwigoAPI

0 commit comments

Comments
 (0)