[FIX] base: fixes http redirection
The 7d85ab1eac refactor of 'ir.http' introduced changes in `web/image` that
caused the route to no longer return early (to avoid data processing steps)
in the case of redirection and that caused `binary_content` to not set the
mimetype of the `ir.attachment` when it was an URL.
This commit fixes those issues, allowing `web/image` to redirect properly.
closes odoo/odoo#30777
This commit is contained in:
@@ -1061,7 +1061,7 @@ class Binary(http.Controller):
|
||||
filename_field=filename_field, download=download, mimetype=mimetype,
|
||||
default_mimetype='image/png', access_token=access_token)
|
||||
|
||||
if status != 200 and download:
|
||||
if status == 301 or (status != 200 and download):
|
||||
return request.env['ir.http']._response_by_status(status, headers, content)
|
||||
if not content:
|
||||
content = base64.b64encode(self.placeholder(image='placeholder.png'))
|
||||
|
||||
@@ -277,7 +277,8 @@ class IrHttp(models.AbstractModel):
|
||||
@classmethod
|
||||
def _binary_ir_attachment_redirect_content(cls, record, default_mimetype='application/octet-stream'):
|
||||
# mainly used for theme images attachemnts
|
||||
status = content = filename = mimetype = filehash = None
|
||||
status = content = filename = filehash = None
|
||||
mimetype = getattr(record, 'mimetype', False)
|
||||
if record.type == 'url' and record.url:
|
||||
# if url in in the form /somehint server locally
|
||||
url_match = re.match("^/(\w+)/(.+)$", record.url)
|
||||
|
||||
+2
-2
@@ -321,11 +321,11 @@ def limited_image_resize(content, width=None, height=None, crop=False, upper_lim
|
||||
"""
|
||||
:param content: bytes (should be an image)
|
||||
"""
|
||||
if content:
|
||||
if content and (width or height):
|
||||
signatures = [b'\xFF\xD8\xFF', b'\x89PNG\r\n\x1A\n']
|
||||
decoded_content = base64.b64decode(content)
|
||||
is_image = any(decoded_content.startswith(signature) for signature in signatures)
|
||||
if (width or height) and is_image:
|
||||
if is_image:
|
||||
height = int(height or 0)
|
||||
width = int(width or 0)
|
||||
if crop:
|
||||
|
||||
Reference in New Issue
Block a user