From b45ba7c2c4b58d6b7d4b8b95d94bebe0504b4f79 Mon Sep 17 00:00:00 2001 From: Francois Date: Mon, 15 Feb 2021 15:14:07 +0100 Subject: [PATCH 1/3] Fixed external sources of images/video contents in Image, VideoPlayer and SvgImage widgets. --- README.md | 4 ++-- remi/gui.py | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 833ce5a9..0742f8df 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,6 @@ At least : * move `url_root` to the right place inside remi (note that this variable should also be accessible from `gui.py`) * ~~make `url_root` an optional parameter which defaults to `""`~~ Currently done in `class App[...]`. * test this feature with https/wss -* continue implementation of some Remi widgets: where hard links are sent to the client (currently done : Image, VideoPlayer, SvgImage, FileFolderItem). -* For `Image`, `VideoPlayer`, `SvgImage` widgets, setters were modified to unconditionally prefix the input src url with `url_root`. This will cause problem for embedding contents from external server/website. +* ~~continue implementation of some Remi widgets: where hard links are sent to the client (currently done : Image, VideoPlayer, SvgImage, FileFolderItem)~~ Everything seems to be ok, please just confirm. +* ~~For `Image`, `VideoPlayer`, `SvgImage` widgets, setters were modified to unconditionally prefix the input src url with `url_root`. This will cause problem for embedding contents from external server/website.~~ Solved by searching the string "://" in the `Image`, `VideoPlayer` and `SvgImage` widgets image/video source: if present don't append the `url_root` prefix, append it otherwise. * ~~issue with no immediate clean solution: all calls (by default 3) to "/res:" in "style.css" are broken as they are not prefixed with "url_root". We should discuss about that.~~ Finally fixed by replacing all three absolute imports by relative imports (/res -> ./res) in style.css. diff --git a/remi/gui.py b/remi/gui.py index 3e0af6ab..0f5ea83d 100644 --- a/remi/gui.py +++ b/remi/gui.py @@ -2930,7 +2930,7 @@ class Image(Widget): @editor_attribute_decorator("WidgetSpecific", '''Image data or url''', 'base64_image', {}) def attr_src(self): return self.attributes.get('src', '') @attr_src.setter - def attr_src(self, value): self.attributes['src'] = url_root+str(value) + def attr_src(self, value): self.attributes['src'] = str(value) if "://" in value else url_root+str(value) @attr_src.deleter def attr_src(self): del self.attributes['src'] @@ -2942,14 +2942,14 @@ def __init__(self, image='', *args, **kwargs): """ super(Image, self).__init__(*args, **kwargs) self.type = 'img' - self.attributes['src'] = url_root+image + self.attributes['src'] = str(image) if "://" in image else url_root+str(image) def set_image(self, image): """ Args: image (str): an url to an image or a base64 data string """ - self.attributes['src'] = url_root+image + self.attributes['src'] = str(image) if "://" in image else url_root+str(image) class Table(Container): @@ -4248,7 +4248,7 @@ class VideoPlayer(Widget): @editor_attribute_decorator("WidgetSpecific", '''Video url''', str, {}) def attr_src(self): return self.attributes.get('src', '') @attr_src.setter - def attr_src(self, value): self.attributes['src'] = url_root+str(value) + def attr_src(self, value): self.attributes['src'] = str(value) if "://" in value else url_root+str(value) @property @editor_attribute_decorator("WidgetSpecific", '''Video poster img''', 'base64_image', {}) @@ -4277,7 +4277,7 @@ def attr_type(self, value): self.attributes['type'] = str(value).lower() def __init__(self, video='', poster=None, autoplay=False, loop=False, *args, **kwargs): super(VideoPlayer, self).__init__(*args, **kwargs) self.type = 'video' - self.attributes['src'] = url_root+video + self.attributes['src'] = str(video) if "://" in video else url_root+str(video) self.attributes['preload'] = 'auto' self.attributes['controls'] = None self.attributes['poster'] = poster @@ -4691,7 +4691,7 @@ def attr_preserveAspectRatio(self): del self.attributes['preserveAspectRatio'] @editor_attribute_decorator("WidgetSpecific", '''Image data or url or a base64 data string, html attribute xlink:href''', 'base64_image', {}) def image_data(self): return self.attributes.get('xlink:href', '') @image_data.setter - def image_data(self, value): self.attributes['xlink:href'] = url_root+str(value) + def image_data(self, value): self.attributes['xlink:href'] = str(value) if "://" in value else url_root+str(value) @image_data.deleter def image_data(self): del self.attributes['xlink:href'] @@ -4707,7 +4707,7 @@ def __init__(self, image_data='', x=0, y=0, w=100, h=100, *args, **kwargs): """ super(SvgImage, self).__init__(*args, **kwargs) self.type = 'image' - self.image_data = url_root+image_data + self.image_data = image_data if "://" in image_data else url_root+image_data self.set_position(x, y) _MixinSvgSize.set_size(self, w, h) From ca0a6e8adab6ee1c61ac20c0533f310a076be50e Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 16 Feb 2021 13:14:51 +0100 Subject: [PATCH 2/3] Fix retro-compatibility scripts (declare url_root in gui.py). --- remi/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remi/gui.py b/remi/gui.py index 0f5ea83d..de16a804 100644 --- a/remi/gui.py +++ b/remi/gui.py @@ -44,7 +44,7 @@ unescape = html.unescape from .server import runtimeInstances - +url_root="" log = logging.getLogger('remi.gui') From 843caef916da1a9913c37159255d51d61aa49402 Mon Sep 17 00:00:00 2001 From: Francois Kneib Date: Fri, 19 Mar 2021 10:56:32 +0100 Subject: [PATCH 3/3] Fix file uploader url. --- remi/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remi/gui.py b/remi/gui.py index de16a804..e59cc27e 100644 --- a/remi/gui.py +++ b/remi/gui.py @@ -1667,7 +1667,7 @@ def set_internal_js(self, app_identifier, net_interface_ip, pending_messages_que }; Remi.prototype.uploadFile = function(widgetID, eventSuccess, eventFail, eventData, file){ - var url = '/%(url_root)s'; + var url = './%(url_root)s'; var xhr = new XMLHttpRequest(); var fd = new FormData(); xhr.open('POST', url, true);