Skip to content

Commit

Permalink
Remove /ui/ route, add fallback 404/500 (#4565)
Browse files Browse the repository at this point in the history
- `/ui` is no longer used (not to be confused with `/ws/ui`.
- Add 404/500 fallback routes for Vue error pages (500 error isn't on the router yet)
  • Loading branch information
sharkykh authored and OmgImAlexis committed Jul 5, 2018
1 parent 25b92dd commit 5fb7d34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `/config` - Help & Info ([#4374](https://github.com/pymedusa/Medusa/pull/4374))
- `/addShows` - Add Shows ([#4564](https://github.com/pymedusa/Medusa/pull/4564))
- `/addRecommended` - Add Recommended Shows ([#4564](https://github.com/pymedusa/Medusa/pull/4564))
- Removed the old `/ui` route ([#4565](https://github.com/pymedusa/Medusa/pull/4565))
- _Simple message describing the improvement, and a link to the pull request._

**Fixes**
Expand Down
1 change: 0 additions & 1 deletion medusa/server/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
PageTemplate,
Schedule,
TokenHandler,
UI,
WebFileBrowser,
WebHandler,
WebRoot,
Expand Down
1 change: 0 additions & 1 deletion medusa/server/web/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from medusa.server.web.core.base import (
BaseHandler,
PageTemplate,
UI,
WebHandler,
WebRoot,
get_lookup,
Expand Down
53 changes: 20 additions & 33 deletions medusa/server/web/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import unicode_literals

import json
import os
import re
import time
Expand All @@ -22,7 +21,6 @@
exception_handler,
helpers,
logger,
ui,
)
from medusa.server.api.v1.core import function_mapper

Expand Down Expand Up @@ -245,7 +243,7 @@ def __init__(self, *args, **kwargs):
def get(self, route, *args, **kwargs):
try:
# route -> method obj
route = route.strip('/').replace('.', '_') or 'index'
route = route.strip('/').replace('.', '_').replace('-', '_') or 'index'
method = getattr(self, route)

results = yield self.async_call(method)
Expand All @@ -261,7 +259,7 @@ def get(self, route, *args, **kwargs):
def post(self, route, *args, **kwargs):
try:
# route -> method obj
route = route.strip('/').replace('.', '_') or 'index'
route = route.strip('/').replace('.', '_').replace('-', '_') or 'index'
method = getattr(self, route)

results = yield self.async_call(method)
Expand Down Expand Up @@ -296,6 +294,24 @@ def __init__(self, *args, **kwargs):
def index(self):
return self.redirect('/{page}/'.format(page=app.DEFAULT_PAGE))

def not_found(self):
"""
Fallback 404 route.
[Converted to VueRouter]
"""
t = PageTemplate(rh=self, filename='index.mako')
return t.render()

def server_error(self):
"""
Fallback 500 route.
[Converted to VueRouter]
"""
t = PageTemplate(rh=self, filename='index.mako')
return t.render()

def robots_txt(self):
"""Keep web crawlers out."""
self.set_header('Content-Type', 'text/plain')
Expand Down Expand Up @@ -349,35 +365,6 @@ def setPosterSortDir(direction):
app.instance.save_config()


@route('/ui(/?.*)')
class UI(WebRoot):
def __init__(self, *args, **kwargs):
super(UI, self).__init__(*args, **kwargs)

@staticmethod
def add_message():
ui.notifications.message('Test 1', 'This is test number 1')
ui.notifications.error('Test 2', 'This is test number 2')

return 'ok'

def get_messages(self):
self.set_header('Cache-Control', 'max-age=0,no-cache,no-store')
self.set_header('Content-Type', 'application/json')
messages = {}
cur_notification_num = 1
for cur_notification in ui.notifications.get_notifications(self.request.remote_ip):
messages['notification-{number}'.format(number=cur_notification_num)] = {
'title': '{0}'.format(cur_notification.title),
'message': '{0}'.format(cur_notification.message),
'type': '{0}'.format(cur_notification.notification_type),
'hash': '{0}'.format(hash(cur_notification)),
}
cur_notification_num += 1

return json.dumps(messages)


class AuthenticatedStaticFileHandler(StaticFileHandler):
def __init__(self, *args, **kwargs):
super(AuthenticatedStaticFileHandler, self).__init__(*args, **kwargs)
Expand Down

0 comments on commit 5fb7d34

Please sign in to comment.