This commit is contained in:
Jürgen Mummert
2025-12-28 11:38:31 +01:00
parent 9edb1e4713
commit 0fd119f873
+23 -12
View File
@@ -132,21 +132,19 @@ class PdfIndexService
{ {
fwrite(STDERR, "[Meili PDF DEBUG] normalizePdfUrl(): {$url}\n"); fwrite(STDERR, "[Meili PDF DEBUG] normalizePdfUrl(): {$url}\n");
if (str_starts_with($url, '/files/') && preg_match('~\.pdf(\?.*)?$~i', $url)) {
$r = preg_replace('~\?.*$~', '', $url);
fwrite(STDERR, "[Meili PDF DEBUG] → direct /files path {$r}\n");
return $r;
}
$decoded = html_entity_decode($url); $decoded = html_entity_decode($url);
$parts = parse_url($decoded); $parts = parse_url($decoded);
if ( // 1) files/...pdf (ohne führenden Slash)
!empty($parts['path']) if (!empty($parts['path']) && str_starts_with($parts['path'], 'files/') && str_ends_with(strtolower($parts['path']), '.pdf')) {
&& str_starts_with($parts['path'], '/files/') $r = '/' . $parts['path'];
&& str_ends_with(strtolower($parts['path']), '.pdf') fwrite(STDERR, "[Meili PDF DEBUG] → relative files path {$r}\n");
) { return $r;
fwrite(STDERR, "[Meili PDF DEBUG] → absolute URL path {$parts['path']}\n"); }
// 2) /files/...pdf
if (!empty($parts['path']) && str_starts_with($parts['path'], '/files/') && str_ends_with(strtolower($parts['path']), '.pdf')) {
fwrite(STDERR, "[Meili PDF DEBUG] → absolute files path {$parts['path']}\n");
return $parts['path']; return $parts['path'];
} }
@@ -157,6 +155,19 @@ class PdfIndexService
parse_str($parts['query'], $query); parse_str($parts['query'], $query);
// 3) Contao 4: ?file=files/...
if (!empty($query['file'])) {
$file = urldecode((string) $query['file']);
$file = ltrim($file, '/');
if (str_starts_with($file, 'files/') && str_ends_with(strtolower($file), '.pdf')) {
$r = '/' . $file;
fwrite(STDERR, "[Meili PDF DEBUG] → file= normalized {$r}\n");
return $r;
}
}
// 4) Contao 5: ?p=...
if (!empty($query['p'])) { if (!empty($query['p'])) {
$p = urldecode((string) $query['p']); $p = urldecode((string) $query['p']);
$r = '/files/' . ltrim($p, '/'); $r = '/files/' . ltrim($p, '/');