diff --git a/composer.json b/composer.json index d9bcc803..7f54d4dd 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "henck/rtf-to-html": "^1.2", "html2text/html2text": "^4.3", "phpoffice/phpword": "^1.2", + "ralouphie/mimey": "^1.0", "smalot/pdfparser": "^2.11" }, "scripts": { diff --git a/composer.lock b/composer.lock index 0ef0edf5..e9bc2df6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b2ea5122778117d13a792a020c986787", + "content-hash": "82ecee0e36d1b1a3fba5a93982fd6d62", "packages": [ { "name": "erusev/parsedown", @@ -302,6 +302,50 @@ }, "time": "2024-08-30T18:03:42+00:00" }, + { + "name": "ralouphie/mimey", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/mimey.git", + "reference": "2a0e997c733b7c2f9f8b61cafb006fd5fb9fa15a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/mimey/zipball/2a0e997c733b7c2f9f8b61cafb006fd5fb9fa15a", + "reference": "2a0e997c733b7c2f9f8b61cafb006fd5fb9fa15a", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mimey\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "PHP package for converting file extensions to MIME types and vice versa.", + "support": { + "issues": "https://github.com/ralouphie/mimey/issues", + "source": "https://github.com/ralouphie/mimey/tree/master" + }, + "time": "2016-09-28T03:36:23+00:00" + }, { "name": "smalot/pdfparser", "version": "v2.12.0", diff --git a/lib/Service/AssistantService.php b/lib/Service/AssistantService.php index 7de7d9fb..d23854a1 100644 --- a/lib/Service/AssistantService.php +++ b/lib/Service/AssistantService.php @@ -439,19 +439,16 @@ public function shareOutputFile(string $userId, int $ocpTaskId, int $fileId): st * @throws NotPermittedException */ private function getTargetFileName(File $file): string { - $mime = mime_content_type($file->fopen('rb')); - $name = $file->getName(); - $ext = ''; - if ($mime === 'image/png') { - $ext = '.png'; - } elseif ($mime === 'image/jpeg') { - $ext = '.jpg'; - } + $mimeType = mime_content_type($file->fopen('rb')); + $fileName = $file->getName(); + + $mimes = new \Mimey\MimeTypes; - if (str_ends_with($name, $ext)) { - return $name; + $extension = $mimes->getExtension($mimeType); + if (is_string($extension) && $extension !== '' && !str_ends_with($fileName, $extension)) { + return $fileName . '.' . $extension; } - return $name . $ext; + return $fileName; } /**