From 68ad3562c4a4fcfb4da95780bece23416dfa448d Mon Sep 17 00:00:00 2001 From: j Date: Sun, 6 Jul 2025 20:44:31 +0100 Subject: [PATCH] add cr2 image support --- pandora/document/fulltext.py | 5 ++++- pandora/document/models.py | 2 +- pandora/document/views.py | 2 +- static/js/utils.js | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pandora/document/fulltext.py b/pandora/document/fulltext.py index 5f2a3e50d..35f74e7b7 100644 --- a/pandora/document/fulltext.py +++ b/pandora/document/fulltext.py @@ -8,7 +8,8 @@ from django.conf import settings logger = logging.getLogger('pandora.' + __name__) -IMAGE_EXTENSIONS = ('png', 'jpg', 'webp', 'heic', 'heif') +IMAGE_EXTENSIONS = ('png', 'jpg') +CONVERT_EXTENSIONS = ('webp', 'heic', 'heif', 'cr2') def extract_text(pdf, page=None): if page is not None: @@ -56,6 +57,8 @@ class FulltextMixin: return extract_text(self.file.path) elif self.extension in IMAGE_EXTENSIONS: return ocr_image(self.file.path) + elif self.extension in CONVERT_EXTENSIONS: + return ocr_image(self.file.path) elif self.extension == 'html': return self.data.get('text', '') return '' diff --git a/pandora/document/models.py b/pandora/document/models.py index 3b3a02629..a4b94497c 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -564,7 +564,7 @@ class Document(models.Model, FulltextMixin): path = os.path.join(folder, '%dp%d,%s.jpg' % (size, page, ','.join(map(str, crop)))) if not os.path.exists(path): resize_image(src, path, size=size) - elif self.extension in ('jpg', 'png', 'gif', 'webp', 'heic', 'heif'): + elif self.extension in ('jpg', 'png', 'gif', 'webp', 'heic', 'heif', 'cr2'): if os.path.exists(src): if size and page: crop = list(map(int, page.split(','))) diff --git a/pandora/document/views.py b/pandora/document/views.py index 8ce0f35b5..1e52fa7e8 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -383,7 +383,7 @@ def file(request, id, name=None): mime_type = mimetypes.guess_type(document.file.path)[0] mime_type = 'image/%s' % document.extension if accept and 'image/' in accept and document.extension in ( - 'webp', 'heif', 'heic', 'avif', 'tiff' + 'webp', 'heif', 'heic', 'avif', 'tiff', ) and mime_type not in accept: image_size = max(document.width, document.height) return HttpFileResponse(document.thumbnail(image_size, accept=accept)) diff --git a/static/js/utils.js b/static/js/utils.js index 0ea3b8ac8..ea142edd0 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -422,6 +422,7 @@ pandora.createLinks = function($element) { pandora.imageExtensions = [ 'avif', + 'cr2', 'gif', 'heic', 'heif', @@ -429,7 +430,7 @@ pandora.imageExtensions = [ 'jpg', 'png', 'tiff', - 'webp' + 'webp', ]; pandora.documentExtensions = [