From 8f3841f7cf9b44f02dfbbeaa467e52327c50ca8c Mon Sep 17 00:00:00 2001 From: rivexe Date: Mon, 18 Mar 2024 14:08:32 +0300 Subject: [PATCH] fix: fixed download error for some formats. a separate method has been allocated for obtaining mime type by format name --- controller/editorcontroller.php | 4 ++-- lib/appconfig.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 3ff9b176..f414b444 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -1257,9 +1257,9 @@ public function download($fileId, $toExtension = null, $template = false) { $fileNameWithoutExt = substr($fileName, 0, strlen($fileName) - strlen($ext) - 1); $newFileName = $fileNameWithoutExt . "." . $toExtension; - $formats = $this->config->formatsSetting(); + $mimeType = $this->config->getMimeType($toExtension); - return new DataDownloadResponse($newData, $newFileName, $formats[$toExtension]["mime"][0]); + return new DataDownloadResponse($newData, $newFileName, $mimeType); } /** diff --git a/lib/appconfig.php b/lib/appconfig.php index 8f570027..07b9cece 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -1432,6 +1432,27 @@ public function getFormats() { return json_decode($formats, true); } + /** + * Get the mime type by format name + * + * @param string $ext - format name + * + * @return string + */ + public function getMimeType($ext) { + $onlyofficeFormats = $this->getFormats(); + $result = "text/plain"; + + foreach ($onlyofficeFormats as $onlyOfficeFormat) { + if ($onlyOfficeFormat["name"] === $ext && !empty($onlyOfficeFormat["mime"])) { + $result = $onlyOfficeFormat["mime"][0]; + break; + } + } + + return $result; + } + /** * DEMO DATA */