Fix root WebDAV alt-import derivative detection

This commit is contained in:
Terranom674
2026-08-19 21:01:00 +02:00
parent fb1f12d608
commit 3fe9527537

View File

@@ -49,18 +49,21 @@ function bratonien_tools_webdav_image_source_info($image_id)
} }
$root_path = ''; $root_path = '';
$root_found = false;
$roots = isset($config['roots']) && is_array($config['roots']) ? $config['roots'] : array(); $roots = isset($config['roots']) && is_array($config['roots']) ? $config['roots'] : array();
foreach ($roots as $root) foreach ($roots as $root)
{ {
if ((int)($root['fileid'] ?? 0) === $root_fileid) if ((int)($root['fileid'] ?? 0) === $root_fileid)
{ {
$root_path = trim((string)($root['webdav_path'] ?? ''), '/'); $root_path = trim((string)($root['webdav_path'] ?? ''), '/');
$root_found = true;
break; break;
} }
} }
if ($root_path === '') return $cache[$image_id] = null; if (!$root_found) return $cache[$image_id] = null;
$webdav_path = $root_path.'/'.$relative_path; $root_is_base = $root_path === '';
$webdav_path = $root_is_base ? $relative_path : $root_path.'/'.$relative_path;
$content_type = ''; $content_type = '';
$size = 0; $size = 0;
$etag = ''; $etag = '';
@@ -90,6 +93,7 @@ function bratonien_tools_webdav_image_source_info($image_id)
'image_id'=>$image_id, 'image_id'=>$image_id,
'connection_id'=>$connection_id, 'connection_id'=>$connection_id,
'webdav_path'=>$webdav_path, 'webdav_path'=>$webdav_path,
'root_is_base'=>$root_is_base,
'content_type'=>$content_type, 'content_type'=>$content_type,
'size'=>$size, 'size'=>$size,
'etag'=>$etag, 'etag'=>$etag,
@@ -415,6 +419,8 @@ function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image,
$info = bratonien_tools_webdav_image_source_info((int)$src_image->id); $info = bratonien_tools_webdav_image_source_info((int)$src_image->id);
if (!$info) return $url; if (!$info) return $url;
if (empty($info['root_is_base']))
{
try try
{ {
$derivative = new DerivativeImage($params, $src_image); $derivative = new DerivativeImage($params, $src_image);
@@ -428,6 +434,7 @@ function bratonien_tools_filter_webdav_derivative_url($url, $params, $src_image,
{ {
error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage()); error_log('Bratonien WebDAV derivative lookup #'.(int)$src_image->id.': '.$e->getMessage());
} }
}
$preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true); $preview_url = bratonien_tools_webdav_image_url((int)$src_image->id, true);
return $preview_url ?: $url; return $preview_url ?: $url;