diff --git a/rest/index.php b/rest/index.php index e7a7aba82d1917ca6dde0491ad0684e3594ddada..e2fe6156a57e02ebaca007bf89875f245071a5c3 100755 --- a/rest/index.php +++ b/rest/index.php @@ -256,11 +256,11 @@ $app->put('/indexingModels/{id}/enable', \IndexingModel\controllers\IndexingMode $app->delete('/indexingModels/{id}', \IndexingModel\controllers\IndexingModelController::class . ':delete'); //Jnlp -$app->post('/test', \ContentManagement\controllers\JnlpController::class . ':test'); $app->post('/jnlp', \ContentManagement\controllers\JnlpController::class . ':generateJnlp'); $app->get('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':renderJnlp'); $app->post('/jnlp/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':processJnlp'); $app->get('/jnlp/lock/{jnlpUniqueId}', \ContentManagement\controllers\JnlpController::class . ':isLockFileExisting'); +$app->get('/onlyOffice/encodedFile', \ContentManagement\controllers\JnlpController::class . ':getEncodedFileFromOnlyOffice'); //Links $app->get('/links/resId/{resId}', \Link\controllers\LinkController::class . ':getByResId'); diff --git a/src/app/contentManagement/controllers/JnlpController.php b/src/app/contentManagement/controllers/JnlpController.php index 82378356200fa6596ed61bcf5b516ba516b2537e..ebbfb96ec4623b8ff867286e5475c3fe08fe907d 100755 --- a/src/app/contentManagement/controllers/JnlpController.php +++ b/src/app/contentManagement/controllers/JnlpController.php @@ -16,6 +16,7 @@ namespace ContentManagement\controllers; use Attachment\models\AttachmentModel; use Docserver\models\DocserverModel; +use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; use SrcCore\controllers\UrlController; @@ -381,28 +382,19 @@ class JnlpController return $response->saveXML(); } - public static function test(Request $request, Response $response) + public static function getEncodedFileFromOnlyOffice(Request $request, Response $response) { + $queryParams = $request->getQueryParams(); - if (($body_stream = file_get_contents("php://input"))===false) { - echo "Bad Request"; + if (!Validator::stringType()->notEmpty()->validate($queryParams['url'])) { + return $response->withStatus(400)->withJson(['errors' => 'Query params url is empty']); } - - $data = json_decode($body_stream, true); - if ($data["status"] == 2 || $data["status"] == 6) { - $downloadUri = $data["url"]; - - if (($new_data = file_get_contents($downloadUri))===false) { - echo "Bad Response"; - } else { - $tmpPath = CoreConfigModel::getTmpPath(); - $fileOnTmp = "tmp_file_onlyoffice_{$data["key"]}.odt"; - file_put_contents($tmpPath.$fileOnTmp, $new_data, LOCK_EX); - // echo $new_data; - //file_put_contents($path_for_save, $new_data, LOCK_EX); - } + + $fileContent = file_get_contents($queryParams['url']); + if ($fileContent == false) { + return $response->withStatus(400)->withJson(['errors' => 'No content found']); } - return $response->withJson(['error' => 0]); + return $response->withJson(['encodedFile' => base64_encode($fileContent)]); } }