Skip to content

Commit

Permalink
Fix app startup and routes
Browse files Browse the repository at this point in the history
Closes #435
  • Loading branch information
Asutosh989 authored and malithsen committed Mar 4, 2018
1 parent 40f49ac commit 65654d5
Show file tree
Hide file tree
Showing 8 changed files with 3,989 additions and 276 deletions.
2 changes: 1 addition & 1 deletion components/core/Main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!flask/bin/python

from REST import *
from Server import socketio, server
from ConfReader import check_conf_availability
import logging

Expand Down
2 changes: 0 additions & 2 deletions components/core/Routes/index.py

This file was deleted.

6 changes: 2 additions & 4 deletions components/core/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
import sys
from gevent import monkey

dir_path = os.path.abspath(__file__)[:-10]
sys.path.append(dir_path+'/Routes')
import index

monkey.patch_all(ssl=False)

server = Flask(__name__)
Expand Down Expand Up @@ -46,3 +42,5 @@ def serve_ui(path):
def serve_ui1():
return send_file(os.path.dirname(os.path.realpath(__file__))+"/ui/index.html")

# Import routes
from routes import *
Empty file added components/core/__init__.py
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sys, os
dir_path = os.path.abspath(__file__)[:-19]
sys.path.append(dir_path)

from flask import Flask
from flask.ext.cors import CORS
from flask import send_file, send_from_directory
Expand All @@ -15,6 +11,7 @@
from DownloadDaemon import starter
from EMail import send_mail
from gevent import monkey
from Server import *

@server.route('/download/start')
def start():
Expand Down Expand Up @@ -68,7 +65,7 @@ def add_download_request():
else:
newDownload = Download(data['link'], g.user.userName)
status = add_download(newDownload)
resp = Response(response='{"status":"'+ status + '"}', status= (200 if status == "success" else 400))
resp = Response(response='{"status":"'+ status + '"}', status=200 if status == "success" else 400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand Down Expand Up @@ -123,7 +120,10 @@ def get_downloads_request(limit):
if token is not None :
try:
status = get_downloads(int(limit))
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand Down
31 changes: 21 additions & 10 deletions components/core/Routes/User.py → components/core/routes/User.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import sys, os
dir_path = os.path.abspath(__file__)[:-15]
sys.path.append(dir_path)

from flask import Flask
from flask.ext.cors import CORS
from flask import send_file, send_from_directory
Expand All @@ -12,7 +8,7 @@
from DownloadManager import *
import urllib.request, urllib.error, urllib.parse, _thread
from gevent import monkey

from Server import *

@server.route('/api/login', methods=['POST'])
def login():
Expand Down Expand Up @@ -117,7 +113,10 @@ def get_users_request():
if token is not None and g.user.auth == AuthLeval.ADMIN:
try:
status = get_users()
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand All @@ -134,7 +133,10 @@ def get_user_signup_requests():
if token is not None and g.user.auth == AuthLeval.ADMIN:
try:
status = get_signup_requests()
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand Down Expand Up @@ -168,7 +170,10 @@ def get_blocked_users_request():
if token is not None and g.user.auth == AuthLeval.ADMIN:
try:
status = get_blocked_users()
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand Down Expand Up @@ -222,7 +227,10 @@ def get_downloads_user_request(limit):
if token is not None :
try:
status = get_downloads_user(g.user.userName, int(limit))
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand All @@ -240,7 +248,10 @@ def get_topten_heaviest_users():
if token is not None and g.user.auth == AuthLeval.ADMIN:
try:
status = get_heavy_users()
resp = Response(response=((json.dumps(status),status=200) if not isinstance(status, str) else ('{"error":"' + status + '"}', status=400)))
if not isinstance(status, str):
resp = Response(response=json.dumps(status),status=200)
else:
resp = Response('{"error":"' + status + '"}', status=400)
except Exception as e:
resp = Response(response='{"error":"' + e.message + '"}', status=400)
resp.headers['token'] = token
Expand Down
1 change: 1 addition & 0 deletions components/core/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ['User', 'Download']
Loading

0 comments on commit 65654d5

Please sign in to comment.