Added Downloads to search index.

This commit is contained in:
orasche committed 2026-08-21 15:44:03 +02:00
1 parent 710f95794c
commit cf7a04ea15
6 files changed
+295 -22

No files matched your search

@@ -13,17 +13,21 @@ use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Http\Stream;
/**
* Forced file download for download records: /download/file/<uid>
* Forced file download for download records, two routes:
*
* This is the frontend target of the "Download" record links from the link
* browser (config.recordLinks.download builds exactly this path). A direct
* fileadmin URL would open PDFs inline; this endpoint streams the file with
* Content-Disposition: attachment, so the browser saves it.
* /download/<slug> - canonical, human-readable (search results, sharing)
* /download/file/<uid> - legacy, kept because the "Download" record links
* from the link browser build exactly this path
* (config.recordLinks.download)
*
* A direct fileadmin URL would open PDFs inline; this endpoint streams the
* file with Content-Disposition: attachment, so the browser saves it.
*
* The file lookup lives in Service\DownloadFileResolver (FAL -> Collateral
* naming convention -> filepath column). Unknown uid, hidden record or
* missing file fall through to the regular pipeline - the reply is then the
* normal 404 page, never a broken download.
* naming convention -> filepath column), which also refuses records flagged
* private_download. Unknown uid/slug, hidden or private record or missing
* file fall through to the regular pipeline - the reply is then the normal
* 404 page, never a broken download.
*/
final class DownloadFileMiddleware implements MiddlewareInterface
{
@@ -31,21 +35,26 @@ final class DownloadFileMiddleware implements MiddlewareInterface
{
try {
$path = $request->getUri()->getPath();
$file = null;
if (preg_match('#^/download/file/(\\d+)/?$#', $path, $matches) === 1) {
$file = DownloadFileResolver::resolve((int)$matches[1]);
if ($file !== null) {
$filename = str_replace(['"', "\r", "\n"], '', $file['name']);
} elseif (preg_match('#^/download/([a-z0-9\\-]+)/?$#', $path, $matches) === 1) {
$file = DownloadFileResolver::resolveBySlug($matches[1]);
}
return new Response(
new Stream($file['path'], 'rb'),
200,
[
'Content-Type' => $file['mimeType'] !== '' ? $file['mimeType'] : 'application/octet-stream',
'Content-Length' => (string)$file['size'],
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
]
);
}
if ($file !== null) {
$filename = str_replace(['"', "\r", "\n"], '', $file['name']);
return new Response(
new Stream($file['path'], 'rb'),
200,
[
'Content-Type' => $file['mimeType'] !== '' ? $file['mimeType'] : 'application/octet-stream',
'Content-Length' => (string)$file['size'],
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
]
);
}
} catch (\Throwable $e) {
// fall through to the regular pipeline