Updated office converter to accept a mimetype argument to avoid yet another file mimetype detection
This commit is contained in:
@@ -35,14 +35,13 @@ def create_image_cache_filename(input_filepath, *args, **kwargs):
|
||||
return None
|
||||
|
||||
|
||||
def convert(input_filepath, output_filepath=None, cleanup_files=False, *args, **kwargs):
|
||||
def convert(input_filepath, output_filepath=None, cleanup_files=False, mimetype=None, *args, **kwargs):
|
||||
size = kwargs.get('size')
|
||||
file_format = kwargs.get('file_format', DEFAULT_FILE_FORMAT)
|
||||
zoom = kwargs.get('zoom', DEFAULT_ZOOM_LEVEL)
|
||||
rotation = kwargs.get('rotation', DEFAULT_ROTATION)
|
||||
page = kwargs.get('page', DEFAULT_PAGE_NUMBER)
|
||||
transformations = kwargs.get('transformations', [])
|
||||
mimetype = kwargs.get('mimetype', None)
|
||||
|
||||
if transformations is None:
|
||||
transformations = []
|
||||
@@ -54,7 +53,7 @@ def convert(input_filepath, output_filepath=None, cleanup_files=False, *args, **
|
||||
return output_filepath
|
||||
|
||||
office_converter = OfficeConverter()
|
||||
office_converter.convert(input_filepath)
|
||||
office_converter.convert(input_filepath, mimetype=mimetype)
|
||||
if office_converter:
|
||||
try:
|
||||
input_filepath = office_converter.output_filepath
|
||||
|
||||
@@ -37,11 +37,14 @@ class OfficeConverter(object):
|
||||
def mimetypes(self):
|
||||
return CONVERTER_OFFICE_FILE_MIMETYPES
|
||||
|
||||
def convert(self, input_filepath):
|
||||
def convert(self, input_filepath, mimetype=None):
|
||||
self.input_filepath = input_filepath
|
||||
|
||||
# Make sure file is of a known office format
|
||||
self.mimetype, self.encoding = get_mimetype(open(self.input_filepath), self.input_filepath, mimetype_only=True)
|
||||
# Make sure file is of a known office format
|
||||
if mimetype:
|
||||
self.mimetype = mimetype
|
||||
else:
|
||||
self.mimetype, self.encoding = get_mimetype(open(self.input_filepath), self.input_filepath, mimetype_only=True)
|
||||
|
||||
if self.mimetype in CONVERTER_OFFICE_FILE_MIMETYPES:
|
||||
# Cache results of conversion
|
||||
|
||||
Reference in New Issue
Block a user