From b1576d0819c6410ccd5116b25ad22e65fd8931e3 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 15 Nov 2016 20:37:21 +0000 Subject: [PATCH] Fix bugs and lost images --- openlp/core/api/endpoint/controller.py | 4 ++-- openlp/core/api/endpoint/pluginhelpers.py | 11 ++++++++--- openlp/core/api/http/wsgiapp.py | 8 ++++---- openlp/plugins/images/endpoint.py | 10 +++++----- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/openlp/core/api/endpoint/controller.py b/openlp/core/api/endpoint/controller.py index d6b156aa9..2b7cf34c2 100644 --- a/openlp/core/api/endpoint/controller.py +++ b/openlp/core/api/endpoint/controller.py @@ -114,8 +114,8 @@ def controller_set(request): return {'results': {'success': True}} -@api_controller_endpoint.route('/controller/{controller}/{action:next|previous}') -@controller_endpoint.route('/{controller}/{action:next|previous}') +@api_controller_endpoint.route('controller/{controller}/{action:next|previous}') +@controller_endpoint.route('{action:next|previous}') @requires_auth def controller_direction(request, controller, action): """ diff --git a/openlp/core/api/endpoint/pluginhelpers.py b/openlp/core/api/endpoint/pluginhelpers.py index b4bc86477..a00dbd68b 100644 --- a/openlp/core/api/endpoint/pluginhelpers.py +++ b/openlp/core/api/endpoint/pluginhelpers.py @@ -95,7 +95,7 @@ def service(request, plugin_name, log): return {'results': {'success': True}} -def display_thumbnails(request, controller_name, log, dimensions, file_name, slide): +def display_thumbnails(request, controller_name, log, dimensions, file_name, slide=None): """ Handles requests for adding a song to the service @@ -125,8 +125,13 @@ def display_thumbnails(request, controller_name, log, dimensions, file_name, sli if controller_name and file_name: file_name = urllib.parse.unquote(file_name) if '..' not in file_name: # no hacking please - full_path = os.path.normpath(os.path.join(AppLocation.get_section_data_path(controller_name), - 'thumbnails', file_name, slide)) + if slide: + full_path = os.path.normpath(os.path.join(AppLocation.get_section_data_path(controller_name), + 'thumbnails', file_name, slide)) + else: + full_path = os.path.normpath(os.path.join(AppLocation.get_section_data_path(controller_name), + + 'thumbnails', file_name)) if os.path.exists(full_path): path, just_file_name = os.path.split(full_path) Registry().get('image_manager').add_image(full_path, just_file_name, None, width, height) diff --git a/openlp/core/api/http/wsgiapp.py b/openlp/core/api/http/wsgiapp.py index 0d33d5b92..c2672e679 100644 --- a/openlp/core/api/http/wsgiapp.py +++ b/openlp/core/api/http/wsgiapp.py @@ -143,10 +143,6 @@ class WSGIApplication(object): """ Find the appropriate URL and run the view function """ - # First look to see if this is a static file request - for route, static_app in self.static_routes.items(): - if re.match(route, request.path): - return request.get_response(static_app) # If not a static route, try the views for route, views in self.route_map.items(): match = re.match(route, request.path) @@ -155,6 +151,10 @@ class WSGIApplication(object): log.debug('Found {method} {url}'.format(method=request.method, url=request.path)) view_func = views[request.method.upper()] return _make_response(view_func(request, **kwargs)) + # Look to see if this is a static file request + for route, static_app in self.static_routes.items(): + if re.match(route, request.path): + return request.get_response(static_app) log.error('URL {url} - Not found'.format(url=request.path)) raise NotFound() diff --git a/openlp/plugins/images/endpoint.py b/openlp/plugins/images/endpoint.py index 77b0a38cd..d0cc11975 100644 --- a/openlp/plugins/images/endpoint.py +++ b/openlp/plugins/images/endpoint.py @@ -67,14 +67,14 @@ def images_service(request): return service(request, 'images', log) -@images_endpoint.route('thumbnails/{dimensions}/{file_name}/{slide}') -def images_thumbnails(request, dimensions, file_name, slide): +# images/thumbnails/320x240/1.jpg +@images_endpoint.route('thumbnails/{dimensions}/{file_name}') +def images_thumbnails(request, dimensions, file_name): """ Return an image to a web page based on a URL :param request: Request object :param dimensions: the image size eg 88x88 - :param file_name: the file name of the image - :param slide: the individual image name + :param file_name: the individual image name :return: """ - return display_thumbnails(request, 'images', log, dimensions, file_name, slide) + return display_thumbnails(request, 'images', log, dimensions, file_name)