-
-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
258 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,70 @@ | ||
from flask import Flask | ||
from flask.ext.cors import CORS | ||
from initializer import server, socketio | ||
from flask import send_file, send_from_directory | ||
from flask import request, jsonify, abort, Response, g | ||
from flask_socketio import SocketIO, join_room | ||
from Auth import * | ||
from Models import * | ||
from DownloadManager import * | ||
import json, urllib.request, urllib.error, urllib.parse, os, _thread | ||
from multiprocessing import Process | ||
from DownloadDaemon import starter | ||
from EMail import send_mail | ||
import sys | ||
from gevent import monkey | ||
|
||
monkey.patch_all(ssl=False) | ||
|
||
server = Flask(__name__) | ||
server.config['SECRET_KEY'] = "123456789" | ||
socketio = SocketIO(server, debug=True, logger=True, engineio_logger=True, ping_timeout=600) | ||
cors = CORS(server) | ||
p = None | ||
verbose = False | ||
|
||
if len(sys.argv) == 2 and sys.argv[1] == '-v': | ||
verbose = True | ||
|
||
def token_validator(token): | ||
user = verify_auth_token(token, server.config['SECRET_KEY']) | ||
if user != None: | ||
g.user = user | ||
token = generate_auth_token(user, server.config['SECRET_KEY']) | ||
return token | ||
return None | ||
from flask_socketio import join_room | ||
import os | ||
from file_sender import sender | ||
from routes import User, Download | ||
|
||
|
||
# socket connections | ||
@socketio.on('join', namespace='/progress') | ||
def on_join(data): | ||
room = data['room'] | ||
if room != '': | ||
join_room(room) | ||
|
||
|
||
# endpoints | ||
|
||
@server.route('/ui/<string:path>') | ||
def serve_ui(path): | ||
return send_from_directory(os.path.dirname(os.path.realpath(__file__))+"/ui", path) | ||
return send_from_directory(os.path.dirname(os.path.realpath(__file__)) + "/ui", path) | ||
|
||
|
||
@server.route('/ui/') | ||
def serve_ui1(): | ||
return send_file(os.path.dirname(os.path.realpath(__file__))+"/ui/index.html") | ||
return send_file(os.path.dirname(os.path.realpath(__file__)) + "/ui/index.html") | ||
|
||
|
||
# download endpoints | ||
server.add_url_rule(rule='/download/start', endpoint='start', view_func=Download.start) | ||
server.add_url_rule(rule='/download/kill', endpoint='kill', view_func=Download.kill) | ||
server.add_url_rule(rule='/api/download', endpoint='add_download_request', view_func=Download.add_download_request, | ||
methods=['POST']) | ||
server.add_url_rule(rule='/api/download/<int:id>', endpoint='remove_download_request', | ||
view_func=Download.remove_download_request, methods=['DELETE']) | ||
server.add_url_rule(rule='/api/download/rate/<int:id>', endpoint='rate_download_request', | ||
view_func=Download.rate_download_request, methods=['POST']) | ||
server.add_url_rule(rule='/api/downloads/<int:limit>', endpoint='get_downloads_request', | ||
view_func=Download.get_downloads_request, methods=['GET']) | ||
server.add_url_rule(rule='/api/download/<int:id>', endpoint='get_download', view_func=Download.get_download, | ||
methods=['GET']) | ||
|
||
# user action api endpoints | ||
server.add_url_rule(rule='/api/login', endpoint='login', view_func=User.login, methods=['POST']) | ||
server.add_url_rule(rule='/api/regularuser', endpoint='regular_user_request', view_func=User.regular_user_request, | ||
methods=['POST']) | ||
server.add_url_rule(rule='/api/user', endpoint='add_user_request', view_func=User.add_user_request, methods=['POST']) | ||
server.add_url_rule(rule='/api/user/<string:username>', endpoint='remove_user_request', | ||
view_func=User.remove_user_request, methods=['DELETE']) | ||
server.add_url_rule(rule='/api/user/<string:username>', endpoint='update_user_request', | ||
view_func=User.update_user_request, methods=['PUT']) | ||
server.add_url_rule(rule='/api/user', endpoint='get_users_request', view_func=User.get_users_request, methods=['GET']) | ||
server.add_url_rule(rule='/api/user/requests', endpoint='get_user_signup_requests', | ||
view_func=User.get_user_signup_requests, methods=['GET']) | ||
server.add_url_rule(rule='/api/user/approve/<string:username>', endpoint='approve_user_request', | ||
view_func=User.approve_user_request, methods=['POST']) | ||
server.add_url_rule(rule='/api/user/blocked', endpoint='get_blocked_users_request', | ||
view_func=User.get_blocked_users_request, methods=['GET']) | ||
server.add_url_rule(rule='/api/user/blocked/<string:username>', endpoint='block_user_request', | ||
view_func=User.block_user_request, methods=['POST']) | ||
server.add_url_rule(rule='/api/user/blocked/<string:username>', endpoint='unblock_user_request', | ||
view_func=User.unblock_user_request, methods=['DELETE']) | ||
server.add_url_rule(rule='/api/user/downloads/<int:limit>', endpoint='get_downloads_user_request', | ||
view_func=User.get_downloads_user_request, methods=['GET']) | ||
server.add_url_rule(rule='/api/user/heavy', endpoint='get_topten_heaviest_users', | ||
view_func=User.get_topten_heaviest_users, methods=['GET']) | ||
|
||
# Import routes | ||
from routes import * | ||
# file sending endpoints | ||
server.add_url_rule(rule='/api/file', endpoint='send_file_from_path', view_func=sender.send_file_from_path, | ||
methods=['GET']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
from flask import Flask | ||
from flask_cors import CORS | ||
from flask_socketio import SocketIO | ||
from gevent import monkey | ||
|
||
from utils.app_constants import SERVER_SECRET_KEY | ||
|
||
monkey.patch_all(ssl=False) | ||
|
||
server = Flask(__name__) | ||
server.config['SECRET_KEY'] = SERVER_SECRET_KEY | ||
socketio = SocketIO(server, debug=True, logger=True, engineio_logger=True, ping_timeout=600) | ||
cors = CORS(server) | ||
p = None | ||
verbose = False | ||
|
||
if len(sys.argv) == 2 and sys.argv[1] == '-v': | ||
verbose = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.