mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-04 02:14:06 +02:00
use parser binary
This commit is contained in:
parent
9d3e175544
commit
334dfb3771
6 changed files with 25 additions and 35 deletions
|
|
@ -28,7 +28,7 @@ class Container {
|
|||
private $connection;
|
||||
private $generator;
|
||||
private $baseUrl;
|
||||
private $parserUrl;
|
||||
private $parserPath;
|
||||
private $storeRoot;
|
||||
private $storeUrl;
|
||||
private $apiRoot;
|
||||
|
|
@ -43,7 +43,7 @@ class Container {
|
|||
Connection $connection,
|
||||
Generator $generator,
|
||||
string $baseUrl,
|
||||
string $parserUrl,
|
||||
string $parserPath,
|
||||
string $storeRoot,
|
||||
string $storeUrl,
|
||||
string $apiRoot,
|
||||
|
|
@ -55,7 +55,7 @@ class Container {
|
|||
$this->connection = $connection;
|
||||
$this->generator = $generator;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->parserUrl = $parserUrl;
|
||||
$this->parserPath = $parserPath;
|
||||
$this->storeRoot = $storeRoot;
|
||||
$this->storeUrl = $storeUrl;
|
||||
$this->apiRoot = $apiRoot;
|
||||
|
|
@ -92,7 +92,7 @@ class Container {
|
|||
}
|
||||
|
||||
public function getRawParser(): RawParser {
|
||||
return new RawParser($this->getParserUrl(), new TempController($this->getApiRoot() . '/temp/'));
|
||||
return new RawParser($this->getParserPath(), new TempController($this->getApiRoot() . '/temp/'));
|
||||
}
|
||||
|
||||
public function getUploadProvider(): UploadProvider {
|
||||
|
|
@ -127,8 +127,8 @@ class Container {
|
|||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
public function getParserUrl(): string {
|
||||
return $this->parserUrl;
|
||||
public function getParserPath(): string {
|
||||
return $this->parserPath;
|
||||
}
|
||||
|
||||
public function getStoreRoot(): string {
|
||||
|
|
|
|||
|
|
@ -16,38 +16,26 @@ use function GuzzleHttp\Psr7\stream_for;
|
|||
*/
|
||||
class RawParser {
|
||||
/** @var string */
|
||||
private $parserUrl;
|
||||
private $parserPath;
|
||||
|
||||
private $tempController;
|
||||
|
||||
public function __construct(string $parserUrl, TempController $tempController) {
|
||||
$this->parserUrl = $parserUrl;
|
||||
public function __construct(string $parserPath, TempController $tempController) {
|
||||
$this->parserPath = $parserPath;
|
||||
$this->tempController = $tempController;
|
||||
}
|
||||
|
||||
public function parse(string $path): ?array {
|
||||
$key = md5($path);
|
||||
$url = $this->tempController->register($key, $path);
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->post($this->parserUrl, [
|
||||
'body' => stream_for($url),
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/octet-stream',
|
||||
],
|
||||
]);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
$this->tempController->unregister($key);
|
||||
$command = $this->parserPath . " " . escapeshellarg($path);
|
||||
$output = shell_exec($command);
|
||||
$result = \GuzzleHttp\json_decode($output, true);
|
||||
if (null === $result) {
|
||||
throw new \Exception('Failed to parse demo, unexpected result from parser');
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
} catch (RequestException $e) {
|
||||
$this->tempController->unregister($key);
|
||||
if (false !== strpos($e->getMessage(), 'cURL error 52')) {
|
||||
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
|
||||
}
|
||||
throw new \Exception('Failed to parse demo, ' . $e->getMessage() . ' ' . $url);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ $db = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
|
|||
$host = getenv('BASE_HOST') ?: '';
|
||||
$storeRoot = getenv('DEMO_ROOT') ?: '';
|
||||
$storeHost = getenv('DEMO_HOST') ?: '';
|
||||
$parserUrl = getenv('PARSER_URL') ?: '';
|
||||
$parserPath = getenv('PARSER_PATH') ?: '';
|
||||
$appRoot = getenv('APP_ROOT') ?: '';
|
||||
$editKey = getenv('EDIT_SECRET') ?: '';
|
||||
$uploadKey = getenv('UPLOAD_KEY') ?: '';
|
||||
|
|
@ -39,7 +39,7 @@ $container = new Container(
|
|||
$db,
|
||||
$generator,
|
||||
'https://' . $host,
|
||||
$parserUrl,
|
||||
$parserPath,
|
||||
$storeRoot,
|
||||
$storeHost,
|
||||
$appRoot,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue