Changed url to api. fixes #173

This commit is contained in:
Ruud
2012-04-29 17:06:05 +02:00
parent c161bdd762
commit cea8395e16
5 changed files with 11 additions and 6 deletions
+7 -1
View File
@@ -15,6 +15,7 @@ from sqlalchemy.orm import scoped_session
from sqlalchemy.orm.session import sessionmaker
from werkzeug.utils import redirect
import os
import time
log = CPLog(__name__)
@@ -73,5 +74,10 @@ def getApiKey():
def page_not_found(error):
index_url = url_for('web.index')
url = getattr(request, 'path')[len(index_url):]
return redirect(index_url + '#' + url)
if url[:3] != 'api':
return redirect(index_url + '#' + url)
else:
time.sleep(2)
return 'Wrong API key used', 404
-1
View File
@@ -1,6 +1,5 @@
from flask.blueprints import Blueprint
from flask.helpers import url_for
from flask.templating import render_template
from werkzeug.utils import redirect
api = Blueprint('api', __name__)
+1 -1
View File
@@ -165,7 +165,7 @@ class Core(Plugin):
return '%s:%d%s' % (cleanHost(host).rstrip('/'), int(port), '/' + Env.setting('url_base').lstrip('/') if Env.setting('url_base') else '')
def createApiUrl(self):
return '%s/%s' % (self.createBaseUrl(), Env.setting('api_key'))
return '%s/api/%s' % (self.createBaseUrl(), Env.setting('api_key'))
def version(self):
ver = fireEvent('updater.info', single = True)
+1 -1
View File
@@ -55,7 +55,7 @@ class Plugin(object):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', self.__class__.__name__)
class_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
path = '%s/static/%s/' % (Env.setting('api_key'), class_name)
path = 'api/%s/static/%s/' % (Env.setting('api_key'), class_name)
addView(path + '<path:filename>', self.showStatic, static = True)
if add_to_head:
+2 -2
View File
@@ -172,13 +172,13 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
# Static path
app.static_folder = os.path.join(base_path, 'couchpotato', 'static')
web.add_url_rule('%s/static/<path:filename>' % api_key,
web.add_url_rule('api/%s/static/<path:filename>' % api_key,
endpoint = 'static',
view_func = app.send_static_file)
# Register modules
app.register_blueprint(web, url_prefix = '%s/' % url_base)
app.register_blueprint(api, url_prefix = '%s/%s/' % (url_base, api_key))
app.register_blueprint(api, url_prefix = '%s/api/%s/' % (url_base, api_key))
# Some logging and fire load event
try: log.info('Starting server on port %(port)s' % config)