From eb7e4d48c9f016575863ab4449ccf45ac31fa3a4 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 23 Apr 2017 16:40:42 +0200 Subject: [PATCH 1/3] Add mimetypes for jp2 and webp Those image formats can be processed by Tesseract, so they are needed for improved Nextcloud OCR. Signed-off-by: Stefan Weil --- resources/config/mimetypemapping.dist.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/config/mimetypemapping.dist.json b/resources/config/mimetypemapping.dist.json index 2b187a6ac85..09be65dd86f 100644 --- a/resources/config/mimetypemapping.dist.json +++ b/resources/config/mimetypemapping.dist.json @@ -71,6 +71,7 @@ "iiq": ["image/x-dcraw"], "impress": ["text/impress"], "java": ["text/x-java-source"], + "jp2": ["image/jp2"], "jpeg": ["image/jpeg"], "jpg": ["image/jpeg"], "jps": ["image/jpeg"], @@ -170,6 +171,7 @@ "vsd": ["application/vnd.visio"], "wav": ["audio/wav"], "webm": ["video/webm"], + "webp": ["image/webp"], "woff": ["application/font-woff"], "wpd": ["application/vnd.wordperfect"], "wmv": ["video/x-ms-wmv"], From c9e08a6445b50259d4450b65cf4ddb1515f762f2 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 25 Apr 2017 18:56:23 +0200 Subject: [PATCH 2/3] Add repair steps for new image mime types Signed-off-by: Stefan Weil --- lib/private/Repair/RepairMimeTypes.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php index 534b5ce2c28..d60b507e932 100644 --- a/lib/private/Repair/RepairMimeTypes.php +++ b/lib/private/Repair/RepairMimeTypes.php @@ -110,6 +110,15 @@ class RepairMimeTypes implements IRepairStep { } } + private function introduceImageTypes() { + $updatedMimetypes = array( + 'jp2' => 'image/jp2', + 'webp' => 'image/webp', + ); + + $this->updateMimetypes($updatedMimetypes); + } + private function introduceWindowsProgramTypes() { $updatedMimetypes = array( 'htaccess' => 'text/plain', @@ -130,6 +139,10 @@ class RepairMimeTypes implements IRepairStep { // NOTE TO DEVELOPERS: when adding new mime types, please make sure to // add a version comparison to avoid doing it every time + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) { + $out->info('Fixed image mime types'); + } + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) { $out->info('Fixed windows program mime types'); } From 8ba67fbe1ec54dd961b8df9c0dda12efb5ca8ebb Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 25 Apr 2017 19:06:31 +0200 Subject: [PATCH 3/3] Add test code for new image mime types Signed-off-by: Stefan Weil --- tests/lib/Repair/RepairMimeTypesTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php index ef1412b2fd2..f30bbdf7d11 100644 --- a/tests/lib/Repair/RepairMimeTypesTest.php +++ b/tests/lib/Repair/RepairMimeTypesTest.php @@ -106,6 +106,23 @@ class RepairMimeTypesTest extends \Test\TestCase { $this->checkEntries($fixedMimeTypes); } + /** + * Test renaming the additional image mime types + */ + public function testRenameImageTypes() { + $currentMimeTypes = [ + ['test.jp2', 'application/octet-stream'], + ['test.webp', 'application/octet-stream'], + ]; + + $fixedMimeTypes = [ + ['test.jp2', 'image/jp2'], + ['test.webp', 'image/webp'], + ]; + + $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); + } + /** * Test renaming the richdocuments additional office mime types */ @@ -163,8 +180,10 @@ class RepairMimeTypesTest extends \Test\TestCase { ['test.sr2', 'image/x-dcraw'], ['test.xrf', 'image/x-dcraw'], ['test.DNG', 'image/x-dcraw'], + ['test.jp2', 'image/jp2'], ['test.jps', 'image/jpeg'], ['test.MPO', 'image/jpeg'], + ['test.webp', 'image/webp'], ['test.conf', 'text/plain'], ['test.cnf', 'text/plain'], ['test.yaml', 'application/yaml'], @@ -215,8 +234,10 @@ class RepairMimeTypesTest extends \Test\TestCase { ['test.sr2', 'image/x-dcraw'], ['test.xrf', 'image/x-dcraw'], ['test.DNG', 'image/x-dcraw'], + ['test.jp2', 'image/jp2'], ['test.jps', 'image/jpeg'], ['test.MPO', 'image/jpeg'], + ['test.webp', 'image/webp'], ['test.conf', 'text/plain'], ['test.cnf', 'text/plain'], ['test.yaml', 'application/yaml'],