fix: improve validation for stereo tool upload (#5409)

This commit is contained in:
Bjarn Bronsveld 2022-05-23 22:13:27 +02:00 committed by GitHub
parent 39898b984a
commit 94f0015b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -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');
});
},

View File

@ -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());
}
}

View File

@ -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()) {