Skip to content
Snippets Groups Projects
Verified Commit 31f7470e authored by Damien's avatar Damien
Browse files

FEAT #13581 TIME 1:20 Get converted file from encoded resource

parent a8cf1755
No related branches found
No related tags found
No related merge requests found
......@@ -153,6 +153,7 @@ $app->get('/civilities', \Contact\controllers\ContactController::class . ':getCi
//Convert
$app->post('/convertedFile', \Convert\controllers\ConvertPdfController::class . ':convertedFile');
$app->get('/convertedFile/{filename}', \Convert\controllers\ConvertPdfController::class . ':getConvertedFileByFilename');
$app->post('/convertedFile/encodedFile', \Convert\controllers\ConvertPdfController::class . ':getConvertedFileFromEncodedFile');
//ContentManagement
$app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp');
......
......@@ -325,4 +325,26 @@ class ConvertPdfController
return $response->withJson($encodedFiles);
}
public function getConvertedFileWithEncodedFile(Request $request, Response $response)
{
$body = $request->getParsedBody();
if (!Validator::stringType()->notEmpty()->validate($body['format'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body format is empty or not a string']);
} elseif (!Validator::stringType()->notEmpty()->validate($body['encodedFile'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body encodedFile is empty']);
}
if (!ConvertPdfController::canConvert(['extension' => $body['format']])) {
return $response->withStatus(400)->withJson(['errors' => 'Format can not be converted']);
}
$convertion = ConvertPdfController::convertFromEncodedResource(['encodedResource' => $body['encodedFile']]);
if (!empty($convertion['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $convertion['errors']]);
}
return $response->withJson($convertion);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment