From 5cf657e9f8a8e74a765544198f6eb955563bcce1 Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Thu, 22 Aug 2024 10:49:32 -0500 Subject: [PATCH] Extend houdini to accept a new header X-Islandora-Input-Args which can contain additional command line parameters to be applied BEFORE the input stream. Update and fix small bug in log output. --- Houdini/src/Controller/HoudiniController.php | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Houdini/src/Controller/HoudiniController.php b/Houdini/src/Controller/HoudiniController.php index 65897679..7c3912ab 100644 --- a/Houdini/src/Controller/HoudiniController.php +++ b/Houdini/src/Controller/HoudiniController.php @@ -83,14 +83,20 @@ public function convertOptions(): BinaryFileResponse public function convert(Request $request) { $this->log->info('Convert request.'); + $this->log->debug('Headers received:'); + $pretty_headers = explode("\r\n", (string)$request->headers); + foreach ($pretty_headers as $h) { + $this->log->debug($h); + } + $this->log->debug('Processing request.'); $fedora_resource = $request->attributes->get('fedora_resource'); - $source_content_type = array_key_exists('Content-Type', $fedora_resource->getHeaders()) ? - $fedora_resource->getHeaders()['Content-Type'] : ''; + $source_content_type = array_key_exists('Content-Type', $fedora_resource->getHeaders()) + ? $fedora_resource->getHeaders()['Content-Type'] : ''; if (is_array($source_content_type)) { $source_content_type = array_pop($source_content_type); } - $this->log->debug('source content type:', ['source_content_type' => $source_content_type]); + $this->log->debug('Content-Type of source data:', ['source_content_type' => $source_content_type]); // Get image as a resource. $body = StreamWrapper::getResource($fedora_resource->getBody()); @@ -98,10 +104,14 @@ public function convert(Request $request) $args = $request->headers->get('X-Islandora-Args'); $this->log->debug("X-Islandora-Args:", ['args' => $args]); + // Input arguments to image convert command are sent as a custom header + $inputargs = $request->headers->get('X-Islandora-Input-Args', ''); + $this->log->debug("X-Islandora-Input-Args:", ['inputargs' => $inputargs]); + // Find the correct image type to return $content_type = null; $content_types = $request->getAcceptableContentTypes(); - $this->log->debug('Content Types:', is_array($args) ? $args : []); + $this->log->debug('Content Types:', is_array($content_types) ? $content_types : []); foreach ($content_types as $type) { if (in_array($type, $this->formats)) { $content_type = $type; @@ -119,9 +129,9 @@ public function convert(Request $request) $format = count($exploded) == 2 ? $exploded[1] : $exploded[0]; // If the source is a PDF, must add the pdf:-[0] to the $cmd_string. if ($source_content_type == "application/pdf") { - $cmd_string = "$this->executable pdf:-[0] $args $format:-"; + $cmd_string = "$this->executable $inputargs pdf:-[0] $args $format:-"; } else { - $cmd_string = "$this->executable - $args $format:-"; + $cmd_string = "$this->executable $inputargs - $args $format:-"; } $this->log->info('Imagemagick Command:', ['cmd' => $cmd_string]);