Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed external sources of images/video contents in Image, VideoPlayer… #435

Open
wants to merge 3 commits into
base: apache_base_url
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 9 additions & 9 deletions remi/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
unescape = html.unescape

from .server import runtimeInstances

url_root=""

log = logging.getLogger('remi.gui')

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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']

Expand All @@ -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):
Expand Down Expand Up @@ -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', {})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']

Expand All @@ -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)

Expand Down