Skip to content

Commit 64cb4ce

Browse files
authored
Merge commit from fork
* Rework Homarus CLI invocation to use better escaping. * Bump PHP version in docs. * Point at the newly released/merged code.
1 parent 6ba190c commit 64cb4ce

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

Diff for: Homarus/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"require": {
77
"ext-ctype": "*",
88
"ext-iconv": "*",
9-
"islandora/crayfish-commons": "^4.0",
9+
"islandora/crayfish-commons": "^4.1",
1010
"lexik/jwt-authentication-bundle": "^2.18",
1111
"symfony/dotenv": "5.4.*",
1212
"symfony/flex": "^1.3.1",

Diff for: Homarus/src/Controller/HomarusController.php

+41-14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Islandora\Crayfish\Commons\CmdExecuteService;
66
use Psr\Log\LoggerInterface;
77
use Symfony\Component\HttpFoundation\BinaryFileResponse;
8+
use Symfony\Component\HttpFoundation\HeaderBag;
89
use Symfony\Component\HttpFoundation\Request;
910
use Symfony\Component\HttpFoundation\Response;
1011

@@ -112,12 +113,20 @@ public function convert(Request $request)
112113
$content_types = $request->getAcceptableContentTypes();
113114
[$content_type, $format] = $this->getFfmpegFormat($content_types);
114115

115-
$cmd_params = "";
116-
if ($format == "mp4") {
117-
$cmd_params = " -vcodec libx264 -preset medium -acodec aac " .
118-
"-strict -2 -ab 128k -ac 2 -async 1 -movflags " .
119-
"faststart -y";
120-
}
116+
$cmd_params = match ($format) {
117+
'mp4' => [
118+
'-vcodec', 'libx264',
119+
'-preset', 'medium',
120+
'-acodec', 'aac',
121+
'-strict', '-2',
122+
'-ab', '128k',
123+
'-ac', '2',
124+
'-async', '1',
125+
'-movflags', 'faststart',
126+
'-y',
127+
],
128+
default => [],
129+
};
121130

122131
$temp_file_path = $this->tempDirectory . basename(parse_url($source, PHP_URL_PATH)) . "." . $format;
123132
$this->log->debug('Tempfile: ' . $temp_file_path);
@@ -139,13 +148,31 @@ public function convert(Request $request)
139148
// Add -loglevel error so large files can be processed.
140149
$args .= ' -loglevel error';
141150
$this->log->debug("X-Islandora-Args:", ['args' => $args]);
142-
$token = $request->headers->get('Authorization');
143-
$headers = "'Authorization: $token'";
144-
$cmd_string = "$this->executable -headers $headers -i $source $args $cmd_params -f $format $temp_file_path";
145-
$this->log->debug('Ffmpeg Command:', ['cmd' => $cmd_string]);
151+
152+
$arg_array = array_filter(explode(' ', $args));
153+
154+
$header_bag = new HeaderBag();
155+
if ($token = $request->headers->get('Authorization')) {
156+
$header_bag->set('Authorization', $token);
157+
}
158+
159+
$cmd = array_merge(
160+
[
161+
$this->executable,
162+
'-headers', $header_bag,
163+
'-i', $source,
164+
],
165+
$arg_array,
166+
$cmd_params,
167+
[
168+
'-f', $format,
169+
$temp_file_path,
170+
],
171+
);
172+
$this->log->debug('Ffmpeg Command:', ['cmd' => $cmd]);
146173

147174
// Return response.
148-
return $this->generateDerivativeResponse($cmd_string, $source, $temp_file_path, $content_type);
175+
return $this->generateDerivativeResponse($cmd, $source, $temp_file_path, $content_type);
149176
}
150177

151178
/**
@@ -176,21 +203,21 @@ private function getFfmpegFormat(array $content_types): array
176203
}
177204

178205
/**
179-
* @param string $cmd_string
206+
* @param array $cmd
180207
* @param string $source
181208
* @param string $path
182209
* @param string $content_type
183210
*
184211
* @return \Symfony\Component\HttpFoundation\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
185212
*/
186213
public function generateDerivativeResponse(
187-
string $cmd_string,
214+
array $cmd,
188215
string $source,
189216
string $path,
190217
string $content_type
191218
) {
192219
try {
193-
$this->cmd->execute($cmd_string, $source);
220+
$this->cmd->execute($cmd, $source);
194221
return (new BinaryFileResponse(
195222
$path,
196223
200,

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ![Crayfish](https://cloud.githubusercontent.com/assets/2371345/15409657/2dfb463a-1dec-11e6-9089-06df94ef3f37.png) Crayfish
22

3-
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg?style=flat-square)](https://php.net/)
3+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/)
44
[![Build Status](https://github.com/islandora/crayfish/actions/workflows/build-dev.yml/badge.svg)](https://github.com/Islandora/Crayfish/actions)
55
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
66
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
@@ -14,7 +14,7 @@ A collection of Islandora 8 microservices, lovingly known as Crayfish. Some of
1414

1515
The minimum requirements for any microservice are
1616

17-
* PHP 7.3+
17+
* PHP 8.0+
1818
* [Composer](https://getcomposer.org/)
1919

2020
Many microservices have extra installation requirements. Please see the README of each microservice for additional details.

0 commit comments

Comments
 (0)