Skip to content
Snippets Groups Projects
Verified Commit a4e0d7f1 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #11875 TIME 4:15 rest for new scanToMaarch (old mcc)

parent a2ba6a0f
No related branches found
No related tags found
No related merge requests found
...@@ -130,6 +130,7 @@ $app->put('/contactsFilling', \Contact\controllers\ContactController::class . ': ...@@ -130,6 +130,7 @@ $app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':
//Convert //Convert
$app->post('/convertedFile', \Convert\controllers\ConvertPdfController::class . ':convertedFile'); $app->post('/convertedFile', \Convert\controllers\ConvertPdfController::class . ':convertedFile');
$app->get('/convertedFile/{filename}', \Convert\controllers\ConvertPdfController::class . ':getConvertedFileByFilename');
//CustomFields //CustomFields
$app->get('/customFields', \CustomField\controllers\CustomFieldController::class . ':get'); $app->get('/customFields', \CustomField\controllers\CustomFieldController::class . ':get');
......
...@@ -114,7 +114,8 @@ trait AcknowledgementReceiptTrait ...@@ -114,7 +114,8 @@ trait AcknowledgementReceiptTrait
'path' => $pathToDocument, 'path' => $pathToDocument,
'data' => ['resId' => $aArgs['resId'], 'contactAddressId' => $contactToProcess, 'userId' => $currentUser['id']] 'data' => ['resId' => $aArgs['resId'], 'contactAddressId' => $contactToProcess, 'userId' => $currentUser['id']]
]); ]);
$mergedDocument['encodedDocument'] = ConvertPdfController::convertFromEncodedResource(['encodedResource' => $mergedDocument['encodedDocument']]); $encodedDocument = ConvertPdfController::convertFromEncodedResource(['encodedResource' => $mergedDocument['encodedDocument']]);
$mergedDocument['encodedDocument'] = $encodedDocument["encodedResource"];
$format = 'pdf'; $format = 'pdf';
if (!empty($mergedDocument['encodedDocument']['errors'])) { if (!empty($mergedDocument['encodedDocument']['errors'])) {
......
...@@ -144,10 +144,10 @@ class ConvertPdfController ...@@ -144,10 +144,10 @@ class ConvertPdfController
public static function convertFromEncodedResource(array $aArgs) public static function convertFromEncodedResource(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['encodedResource']); ValidatorModel::notEmpty($aArgs, ['encodedResource']);
ValidatorModel::stringType($aArgs, ['encodedResource']); ValidatorModel::stringType($aArgs, ['encodedResource', 'context']);
$tmpPath = CoreConfigModel::getTmpPath(); $tmpPath = CoreConfigModel::getTmpPath();
$tmpFilename = 'converting' . rand(); $tmpFilename = 'converting' . rand() . '_' . rand();
file_put_contents($tmpPath . $tmpFilename, base64_decode($aArgs['encodedResource'])); file_put_contents($tmpPath . $tmpFilename, base64_decode($aArgs['encodedResource']));
...@@ -159,11 +159,19 @@ class ConvertPdfController ...@@ -159,11 +159,19 @@ class ConvertPdfController
return ['errors' => '[ConvertPdf] Conversion failed ! '. implode(" ", $output)]; return ['errors' => '[ConvertPdf] Conversion failed ! '. implode(" ", $output)];
} }
$resource = file_get_contents("{$tmpPath}{$tmpFilename}.pdf");
unlink("{$tmpPath}{$tmpFilename}"); unlink("{$tmpPath}{$tmpFilename}");
unlink("{$tmpPath}{$tmpFilename}.pdf");
return base64_encode($resource); $resource = file_get_contents("{$tmpPath}{$tmpFilename}.pdf");
$aReturn = [];
$aReturn["encodedResource"] = base64_encode($resource);
if ($aArgs['context'] == 'scan') {
$aReturn["tmpFilename"] = $tmpFilename.'.pdf';
} else {
unlink("{$tmpPath}{$tmpFilename}.pdf");
}
return $aReturn;
} }
public static function getConvertedPdfById(array $aArgs) public static function getConvertedPdfById(array $aArgs)
...@@ -224,10 +232,10 @@ class ConvertPdfController ...@@ -224,10 +232,10 @@ class ConvertPdfController
$body = $request->getParsedBody(); $body = $request->getParsedBody();
if (!Validator::notEmpty()->validate($body['name'])) { if (!Validator::notEmpty()->validate($body['name'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body name is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'Body name is empty']);
} }
if (!Validator::notEmpty()->validate($body['base64'])) { if (!Validator::notEmpty()->validate($body['base64'])) {
return $response->withStatus(400)->withJson(['errors' => 'Body base64 is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'Body base64 is empty']);
} }
$file = base64_decode($body['base64']); $file = base64_decode($body['base64']);
...@@ -237,7 +245,15 @@ class ConvertPdfController ...@@ -237,7 +245,15 @@ class ConvertPdfController
$size = strlen($file); $size = strlen($file);
if (strtolower($ext) == 'pdf' && strtolower($mimeType) == 'application/pdf') { if (strtolower($ext) == 'pdf' && strtolower($mimeType) == 'application/pdf') {
return $response->withJson(['encodedResource' => $body['base64']]); $return['encodedResource'] = $body['base64'];
if ($body['context'] == 'scan') {
$tmpPath = CoreConfigModel::getTmpPath();
$tmpFilename = 'scan_converting' . rand() . '.pdf';
file_put_contents($tmpPath . $tmpFilename, $file);
$return['tmpFilename'] = $tmpFilename;
}
return $response->withJson($return);
} else { } else {
$fileAccepted = StoreController::isFileAllowed(['extension' => $ext, 'type' => $mimeType]); $fileAccepted = StoreController::isFileAllowed(['extension' => $ext, 'type' => $mimeType]);
$maxFilesizeMo = ini_get('upload_max_filesize'); $maxFilesizeMo = ini_get('upload_max_filesize');
...@@ -251,12 +267,26 @@ class ConvertPdfController ...@@ -251,12 +267,26 @@ class ConvertPdfController
return $response->withStatus(400)->withJson(['errors' => 'File accepted but can not be converted in pdf']); return $response->withStatus(400)->withJson(['errors' => 'File accepted but can not be converted in pdf']);
} }
$convertion = ConvertPdfController::convertFromEncodedResource(['encodedResource' => $body['base64']]); $convertion = ConvertPdfController::convertFromEncodedResource(['encodedResource' => $body['base64'], 'context' => $body['context']]);
if (empty($convertion['errors'])) { if (empty($convertion['errors'])) {
return $response->withJson(['encodedResource' => $convertion]); return $response->withJson($convertion);
} else { } else {
return $response->withStatus(400)->withJson($convertion); return $response->withStatus(400)->withJson($convertion);
} }
} }
} }
public function getConvertedFileByFilename(Request $request, Response $response, array $aArgs)
{
$tmpPath = CoreConfigModel::getTmpPath();
if (!file_exists("{$tmpPath}{$aArgs['filename']}")) {
return $response->withStatus(400)->withJson(['errors' => 'File does not exists']);
}
$resource = file_get_contents("{$tmpPath}{$aArgs['filename']}");
unlink("{$tmpPath}{$aArgs['filename']}");
return $response->withJson(['encodedResource' => base64_encode($resource)]);
}
} }
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