diff --git a/addons/web_editor/models/ir_attachment.py b/addons/web_editor/models/ir_attachment.py index 36c44320c48..7a7d9f83111 100644 --- a/addons/web_editor/models/ir_attachment.py +++ b/addons/web_editor/models/ir_attachment.py @@ -26,13 +26,23 @@ class IrAttachment(models.Model): @api.depends('mimetype', 'url', 'name') def _compute_image_src(self): for attachment in self: + # Only add a src for supported images if attachment.mimetype not in ['image/gif', 'image/jpe', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/svg+xml']: attachment.image_src = False + continue + + if attachment.type == 'url': + attachment.image_src = attachment.url else: - attachment.image_src = attachment.url or '/web/image/%s/%s' % ( - attachment.id, - url_quote(attachment.name or ''), - ) + # Adding unique in URLs for cache-control + unique = attachment.checksum[:8] + if attachment.url: + # For attachments-by-url, unique is used as a cachebuster. They + # currently do not leverage max-age headers. + attachment.image_src = '%s?unique=%s' % (attachment.url, unique) + else: + name = url_quote(attachment.name) + attachment.image_src = '/web/image/%s-%s/%s' % (attachment.id, unique, name) @api.depends('datas') def _compute_image_size(self): diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index 87fac3cd640..3ccc9016a02 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -379,7 +379,12 @@ var FileWidget = SearchableMediaWidget.extend({ }).open(); optimizeDialog.on('attachment_updated', self, function (ev) { optimizeDialog.off('closed'); - resolve(ev.data); + if (self.$media[0].getAttribute('src') === attachment.image_src) { + self.$media[0].src = ev.data.image_src; + } + Object.assign(attachment, ev.data); + $attachmentCell.find('img')[0].src = attachment.image_src; + resolve(attachment); }); optimizeDialog.on('closed', self, function () { self.noSave = true;