fix: improve validation for stereo tool upload (#5409)
This commit is contained in:
parent
39898b984a
commit
94f0015b22
|
@ -157,10 +157,14 @@ export default {
|
|||
|
||||
this.flow.on('error', (message, file, chunk) => {
|
||||
console.error(message, file, chunk);
|
||||
|
||||
let messageJson = JSON.parse(message);
|
||||
|
||||
file.error = messageJson.message.split(': ')[1];
|
||||
this.$emit('error', file, messageJson);
|
||||
});
|
||||
|
||||
this.flow.on('complete', () => {
|
||||
this.files = [];
|
||||
this.$emit('complete');
|
||||
});
|
||||
},
|
||||
|
|
|
@ -10,6 +10,8 @@ use App\Http\ServerRequest;
|
|||
use App\Radio\StereoTool;
|
||||
use App\Service\Flow;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
final class PostAction
|
||||
{
|
||||
|
@ -36,6 +38,23 @@ final class PostAction
|
|||
|
||||
chmod($binaryPath, 0744);
|
||||
|
||||
$process = new Process([$binaryPath, '--help']);
|
||||
$process->setWorkingDirectory(dirname($binaryPath));
|
||||
$process->setTimeout(5.0);
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
unlink($binaryPath);
|
||||
throw new RuntimeException('Incompatible binary for StereoTool was uploaded.');
|
||||
}
|
||||
|
||||
preg_match('/STEREO TOOL ([.\d]+) CONSOLE APPLICATION/i', $process->getErrorOutput(), $matches);
|
||||
|
||||
if (!$matches[1]) {
|
||||
unlink($binaryPath);
|
||||
throw new RuntimeException('Unexpected help output received from Stereo Tool.');
|
||||
}
|
||||
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ final class StereoTool
|
|||
|
||||
$process = new Process([$binaryPath, '--help']);
|
||||
$process->setWorkingDirectory(dirname($binaryPath));
|
||||
$process->setTimeout(5.0);
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
|
|
Loading…
Reference in New Issue