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

FEAT #9906 Original content

parent 7174098d
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,7 @@ $app->get('/administration', \SrcCore\controllers\CoreController::class . ':getA ...@@ -71,6 +71,7 @@ $app->get('/administration', \SrcCore\controllers\CoreController::class . ':getA
$app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create'); $app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create');
$app->get('/resources/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getByResId'); $app->get('/resources/{resId}/attachments', \Attachment\controllers\AttachmentController::class . ':getByResId');
$app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent'); $app->get('/res/{resIdMaster}/attachments/{resId}/content', \Attachment\controllers\AttachmentController::class . ':getFileContent');
$app->get('/resources/{resId}/attachments/{id}/originalContent', \Attachment\controllers\AttachmentController::class . ':getOriginalFileContent');
$app->get('/res/{resIdMaster}/attachments/{resId}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent'); $app->get('/res/{resIdMaster}/attachments/{resId}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent');
//AutoComplete //AutoComplete
...@@ -255,6 +256,7 @@ $app->post('/resources', \Resource\controllers\ResController::class . ':create') ...@@ -255,6 +256,7 @@ $app->post('/resources', \Resource\controllers\ResController::class . ':create')
$app->post('/res', \Resource\controllers\ResController::class . ':createRes'); $app->post('/res', \Resource\controllers\ResController::class . ':createRes');
$app->post('/resExt', \Resource\controllers\ResController::class . ':createExt'); $app->post('/resExt', \Resource\controllers\ResController::class . ':createExt');
$app->get('/res/{resId}/content', \Resource\controllers\ResController::class . ':getFileContent'); $app->get('/res/{resId}/content', \Resource\controllers\ResController::class . ':getFileContent');
$app->get('/resources/{resId}/originalContent', \Resource\controllers\ResController::class . ':getOriginalFileContent');
$app->get('/res/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent'); $app->get('/res/{resId}/thumbnail', \Resource\controllers\ResController::class . ':getThumbnailContent');
$app->get('/res/{resId}/acknowledgementReceipt/{id}', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':getAcknowledgementReceipt'); $app->get('/res/{resId}/acknowledgementReceipt/{id}', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':getAcknowledgementReceipt');
$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus'); $app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus');
......
...@@ -356,6 +356,73 @@ class AttachmentController ...@@ -356,6 +356,73 @@ class AttachmentController
return $response->withHeader('Content-Type', $mimeType); return $response->withHeader('Content-Type', $mimeType);
} }
public function getOriginalFileContent(Request $request, Response $response, array $args)
{
if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$attachment = AttachmentModel::getOnView([
'select' => ['res_id', 'res_id_version', 'docserver_id', 'path', 'filename'],
'where' => ['res_id = ? or res_id_version = ?', 'res_id_master = ?', 'status not in (?)'],
'data' => [$args['id'], $args['id'], $args['resId'], ['DEL', 'OBS']],
'limit' => 1
]);
if (empty($attachment[0])) {
return $response->withStatus(403)->withJson(['errors' => 'Attachment not found']);
}
$attachmentTodisplay = $attachment[0];
$id = (empty($attachmentTodisplay['res_id']) ? $attachmentTodisplay['res_id_version'] : $attachmentTodisplay['res_id']);
$document['docserver_id'] = $attachmentTodisplay['docserver_id'];
$document['path'] = $attachmentTodisplay['path'];
$document['filename'] = $attachmentTodisplay['filename'];
$document['fingerprint'] = $attachmentTodisplay['fingerprint'];
$docserver = DocserverModel::getByDocserverId(['docserverId' => $document['docserver_id'], 'select' => ['path_template', 'docserver_type_id']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $document['path']) . $document['filename'];
if (!file_exists($pathToDocument)) {
return $response->withStatus(404)->withJson(['errors' => 'Attachment not found on docserver']);
}
$docserverType = DocserverTypeModel::getById(['id' => $docserver['docserver_type_id'], 'select' => ['fingerprint_mode']]);
$fingerprint = StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType['fingerprint_mode']]);
if (!empty($document['fingerprint']) && $document['fingerprint'] != $fingerprint) {
return $response->withStatus(400)->withJson(['errors' => 'Fingerprints do not match']);
}
if (empty($fileContent)) {
$fileContent = file_get_contents($pathToDocument);
}
if ($fileContent === false) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($fileContent);
$pathInfo = pathinfo($pathToDocument);
$response->write($fileContent);
$response = $response->withAddedHeader('Content-Disposition', "inline; filename=maarch.{$pathInfo['extension']}");
HistoryController::add([
'tableName' => 'res_attachments',
'recordId' => $args['resId'],
'eventType' => 'VIEW',
'info' => _ATTACH_DISPLAYING . " : {$id}",
'moduleId' => 'attachments',
'eventId' => 'resview',
]);
return $response->withHeader('Content-Type', $mimeType);
}
public static function getEncodedDocument(array $aArgs) public static function getEncodedDocument(array $aArgs)
{ {
ValidatorModel::notEmpty($aArgs, ['id']); ValidatorModel::notEmpty($aArgs, ['id']);
......
...@@ -391,6 +391,80 @@ class ResController ...@@ -391,6 +391,80 @@ class ResController
return $response->withHeader('Content-Type', $mimeType); return $response->withHeader('Content-Type', $mimeType);
} }
public function getOriginalFileContent(Request $request, Response $response, array $aArgs)
{
if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => [$aArgs['resId']], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$document = ResModel::getById(['select' => ['docserver_id', 'path', 'filename'], 'resId' => $aArgs['resId']]);
$extDocument = ResModel::getExtById(['select' => ['category_id', 'alt_identifier'], 'resId' => $aArgs['resId']]);
if (empty($document) || empty($extDocument)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
if ($extDocument['category_id'] == 'outgoing') {
$attachment = AttachmentModel::getOnView([
'select' => ['res_id', 'res_id_version', 'docserver_id', 'path', 'filename', 'fingerprint'],
'where' => ['res_id_master = ?', 'attachment_type = ?', 'status not in (?)'],
'data' => [$aArgs['resId'], 'outgoing_mail', ['DEL', 'OBS']],
'limit' => 1
]);
if (!empty($attachment[0])) {
$document['docserver_id'] = $attachment[0]['docserver_id'];
$document['path'] = $attachment[0]['path'];
$document['filename'] = $attachment[0]['filename'];
$document['fingerprint'] = $attachment[0]['fingerprint'];
}
}
$docserver = DocserverModel::getByDocserverId(['docserverId' => $document['docserver_id'], 'select' => ['path_template', 'docserver_type_id']]);
if (empty($docserver['path_template']) || !file_exists($docserver['path_template'])) {
return $response->withStatus(400)->withJson(['errors' => 'Docserver does not exist']);
}
$pathToDocument = $docserver['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $document['path']) . $document['filename'];
if (!file_exists($pathToDocument)) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
$docserverType = DocserverTypeModel::getById(['id' => $docserver['docserver_type_id'], 'select' => ['fingerprint_mode']]);
$fingerprint = StoreController::getFingerPrint(['filePath' => $pathToDocument, 'mode' => $docserverType['fingerprint_mode']]);
if (!empty($document['fingerprint']) && $document['fingerprint'] != $fingerprint) {
return $response->withStatus(400)->withJson(['errors' => 'Fingerprints do not match']);
}
if (empty($fileContent)) {
$fileContent = file_get_contents($pathToDocument);
}
if ($fileContent === false) {
return $response->withStatus(404)->withJson(['errors' => 'Document not found on docserver']);
}
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($fileContent);
$pathInfo = pathinfo($pathToDocument);
$response->write($fileContent);
$response = $response->withAddedHeader('Content-Disposition', "inline; filename=maarch.{$pathInfo['extension']}");
ListInstanceModel::update([
'postSet' => ['viewed' => 'viewed + 1'],
'where' => ['item_id = ?', 'item_mode = ?', 'res_id = ?'],
'data' => [$GLOBALS['userId'], 'cc', $aArgs['resId']]
]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $aArgs['resId'],
'eventType' => 'VIEW',
'info' => _DOC_DISPLAYING . " : {$aArgs['resId']}",
'moduleId' => 'res',
'eventId' => 'resview',
]);
return $response->withHeader('Content-Type', $mimeType);
}
public function getThumbnailContent(Request $request, Response $response, array $aArgs) public function getThumbnailContent(Request $request, Response $response, array $aArgs)
{ {
if (!Validator::intVal()->validate($aArgs['resId'])) { if (!Validator::intVal()->validate($aArgs['resId'])) {
......
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