From 86c12686e40a3c55ade382b377d087554582a213 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Mon, 23 Jul 2018 03:12:24 +0530 Subject: [PATCH 1/9] refactored api end point declarations Signed-off-by: Nirmal Sarswat --- components/core/Server.py | 98 ++++++++++++++++---------- components/core/file_sender/sender.py | 2 +- components/core/initializer.py | 19 +++++ components/core/routes/Download.py | 53 ++++---------- components/core/routes/User.py | 55 ++++++--------- components/core/utils/__init__.py | 0 components/core/utils/app_constants.py | 1 + components/core/utils/token_utils.py | 12 ++++ 8 files changed, 131 insertions(+), 109 deletions(-) create mode 100644 components/core/initializer.py create mode 100644 components/core/utils/__init__.py create mode 100644 components/core/utils/app_constants.py create mode 100644 components/core/utils/token_utils.py diff --git a/components/core/Server.py b/components/core/Server.py index d1df3f3c..7063f6dd 100644 --- a/components/core/Server.py +++ b/components/core/Server.py @@ -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/') 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/', endpoint='remove_download_request', + view_func=Download.remove_download_request, methods=['DELETE']) +server.add_url_rule(rule='/api/download/rate/', endpoint='rate_download_request', + view_func=Download.rate_download_request, methods=['POST']) +server.add_url_rule(rule='/api/downloads/', endpoint='get_downloads_request', + view_func=Download.get_downloads_request, methods=['GET']) +server.add_url_rule(rule='/api/download/', 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/', endpoint='remove_user_request', + view_func=User.remove_user_request, methods=['DELETE']) +server.add_url_rule(rule='/api/user/', 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/', 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/', endpoint='block_user_request', + view_func=User.block_user_request, methods=['POST']) +server.add_url_rule(rule='/api/user/blocked/', endpoint='unblock_user_request', + view_func=User.unblock_user_request, methods=['DELETE']) +server.add_url_rule(rule='/api/user/downloads/', 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']) diff --git a/components/core/file_sender/sender.py b/components/core/file_sender/sender.py index 9e7b265d..5541bffb 100644 --- a/components/core/file_sender/sender.py +++ b/components/core/file_sender/sender.py @@ -1,7 +1,7 @@ from flask import Response, request, send_file from DownloadManager import get_id_from_gid, get_download_path, get_download_name_from_id import logging -from Server import token_validator +from utils.token_utils import token_validator def send_file_from_path(): diff --git a/components/core/initializer.py b/components/core/initializer.py new file mode 100644 index 00000000..90733ff1 --- /dev/null +++ b/components/core/initializer.py @@ -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 \ No newline at end of file diff --git a/components/core/routes/Download.py b/components/core/routes/Download.py index 5cc77909..7d8495f4 100644 --- a/components/core/routes/Download.py +++ b/components/core/routes/Download.py @@ -1,46 +1,32 @@ -from flask import Flask -from flask.ext.cors import CORS -from flask import send_file, send_from_directory -from flask import request, jsonify, abort, Response, g -from flask_socketio import SocketIO, join_room +from flask import send_file +from flask import request, Response, g from Auth import * -from Models import * from DownloadManager import * -import json, urllib.request, urllib.error, urllib.parse, _thread +import json, urllib.request, urllib.error, urllib.parse from multiprocessing import Process from DownloadDaemon import starter -from EMail import send_mail -from gevent import monkey -from Server import * -from file_sender import sender +from utils.app_constants import server_secret_key +from utils.token_utils import token_validator +from initializer import socketio -@server.route('/download/start') def start(): try: token = request.headers['key'] - if str(token) != server.config['SECRET_KEY']: + if str(token) != server_secret_key: return "{'error':'not authorized'}", 403 global p p = Process(target=starter, args=(socketio,)) p.start() return '{"status":"' + str(p.pid) + '"}' except Exception as e: - return '{"error":"' + e.message + '"}', 400 + return '{"error":"' + str(e) + '"}', 400 -@socketio.on('join', namespace='/progress') -def on_join(data): - room = data['room'] - if room != '': - join_room(room) - - -@server.route('/download/kill') def kill(): try: token = request.headers['key'] - if str(token) != server.config['SECRET_KEY']: + if str(token) != server_secret_key: return "{'error':'not authorized'}", 403 if p is not None: p.terminate() @@ -55,10 +41,9 @@ def kill(): else: return '{"error":"error"}' except Exception as e: - return '{"error":"' + e.message + '"}', 400 + return '{"error":"' + str(e) + '"}', 400 -@server.route('/api/download', methods=['POST']) def add_download_request(): token = token_validator(request.headers['token']) if token is not None: @@ -71,7 +56,7 @@ def add_download_request(): status = add_download(newDownload) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -81,7 +66,6 @@ def add_download_request(): return '{"error":"token error"}', 403 -@server.route('/api/download/', methods=['DELETE']) def remove_download_request(id): token = token_validator(request.headers['token']) if token is not None: @@ -89,7 +73,7 @@ def remove_download_request(id): status = remove_download(id, g.user.userName) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -99,7 +83,6 @@ def remove_download_request(id): return '{"error":"token error"}', 403 -@server.route('/api/download/rate/', methods=['POST']) def rate_download_request(id): token = token_validator(request.headers['token']) if token is not None: @@ -108,7 +91,7 @@ def rate_download_request(id): status = rate_download(id, g.user.userName, data['rate']) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -118,7 +101,6 @@ def rate_download_request(id): return '{"error":"token error"}', 403 -@server.route('/api/downloads/', methods=['GET']) def get_downloads_request(limit): token = token_validator(request.headers['token']) if token is not None: @@ -129,7 +111,7 @@ def get_downloads_request(limit): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -139,7 +121,6 @@ def get_downloads_request(limit): return '{"error":"token error"}', 403 -@server.route('/api/download/', methods=['GET']) def get_download(id): token = token_validator(request.headers['token']) if token is not None: @@ -152,13 +133,9 @@ def get_download(id): else: return '{"error":"file not found"}', 404 except Exception as e: - resp = Response(response="{'error':'" + e.message + "'}", status=400) + resp = Response(response="{'error':'" + str(e) + "'}", status=400) return resp elif token is not None: return '{"error":"not authorized"}', 403 else: return '{"error":"token error"}', 403 - - -# register endpoints -server.add_url_rule('/api/file', 'send_file_from_path', sender.send_file_from_path, methods=['GET']) diff --git a/components/core/routes/User.py b/components/core/routes/User.py index 8a8fbce4..9b9e958f 100644 --- a/components/core/routes/User.py +++ b/components/core/routes/User.py @@ -1,23 +1,21 @@ -from flask import Flask -from flask.ext.cors import CORS -from flask import send_file, send_from_directory -from flask import request, jsonify, abort, Response, g -from flask_socketio import SocketIO, join_room +from flask import json +from flask import request, abort, Response, g from Auth import * +from EMail import send_mail from Models import * from DownloadManager import * -import urllib.request, urllib.error, urllib.parse, _thread -from gevent import monkey -from Server import * +import _thread +from utils.token_utils import token_validator +from utils.app_constants import server_secret_key + -@server.route('/api/login', methods=['POST']) def login(): userName = request.form['user_name'] password = request.form['password'] if user_login(userName, password): if check_approved(userName, password): user = get_user(userName) - token = generate_auth_token(user, server.config['SECRET_KEY']) + token = generate_auth_token(user, server_secret_key) resp = Response(response='{"auth":"'+ str(user.auth) + '"}',status=200) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' @@ -29,7 +27,6 @@ def login(): abort(403) -@server.route('/api/regularuser', methods=['POST']) def regular_user_request(): data = request.get_json(force=True) try: @@ -45,7 +42,6 @@ def regular_user_request(): return resp -@server.route('/api/user', methods=['POST']) def add_user_request(): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -59,7 +55,7 @@ def add_user_request(): else: resp = Response(response='{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -69,7 +65,6 @@ def add_user_request(): return '{"error":"token error"}', 403 -@server.route('/api/user/', methods=['DELETE']) def remove_user_request(username): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -77,7 +72,7 @@ def remove_user_request(username): status = remove_user(username) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -87,7 +82,6 @@ def remove_user_request(username): return '{"error":"token error"}', 403 -@server.route('/api/user/', methods=['PUT']) def update_user_request(username): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -97,7 +91,7 @@ def update_user_request(username): status = update_user(newUser, username) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -107,7 +101,6 @@ def update_user_request(username): return '{"error":"token error"}', 403 -@server.route('/api/user', methods=['GET']) def get_users_request(): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -118,7 +111,7 @@ def get_users_request(): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -127,7 +120,7 @@ def get_users_request(): else: return '{"error":"token error"}', 403 -@server.route('/api/user/requests', methods=['GET']) + def get_user_signup_requests(): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -138,7 +131,7 @@ def get_user_signup_requests(): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -147,7 +140,7 @@ def get_user_signup_requests(): else: return '{"error":"token error"}', 403 -@server.route('/api/user/approve/', methods=['POST']) + def approve_user_request(username): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -155,7 +148,7 @@ def approve_user_request(username): status = approve_user(username) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -164,7 +157,7 @@ def approve_user_request(username): else: return '{"error":"token error"}', 403 -@server.route('/api/user/blocked', methods=['GET']) + def get_blocked_users_request(): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -175,7 +168,7 @@ def get_blocked_users_request(): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -185,7 +178,6 @@ def get_blocked_users_request(): return '{"error":"token error"}', 403 -@server.route('/api/user/blocked/', methods=['POST']) def block_user_request(username): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -193,7 +185,7 @@ def block_user_request(username): status = block_user(username) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -203,7 +195,6 @@ def block_user_request(username): return '{"error":"token error"}', 403 -@server.route('/api/user/blocked/', methods=['DELETE']) def unblock_user_request(username): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -211,7 +202,7 @@ def unblock_user_request(username): status = unblock_user(username) 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 = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -221,7 +212,6 @@ def unblock_user_request(username): return '{"error":"token error"}', 403 -@server.route('/api/user/downloads/', methods=['GET']) def get_downloads_user_request(limit): token = token_validator(request.headers['token']) if token is not None : @@ -232,7 +222,7 @@ def get_downloads_user_request(limit): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp @@ -242,7 +232,6 @@ def get_downloads_user_request(limit): return '{"error":"token error"}', 403 -@server.route('/api/user/heavy', methods=['GET']) def get_topten_heaviest_users(): token = token_validator(request.headers['token']) if token is not None and g.user.auth == AuthLeval.ADMIN: @@ -253,7 +242,7 @@ def get_topten_heaviest_users(): else: resp = Response('{"error":"' + status + '"}', status=400) except Exception as e: - resp = Response(response='{"error":"' + e.message + '"}', status=400) + resp = Response(response='{"error":"' + str(e) + '"}', status=400) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' return resp diff --git a/components/core/utils/__init__.py b/components/core/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/components/core/utils/app_constants.py b/components/core/utils/app_constants.py new file mode 100644 index 00000000..cd0a360f --- /dev/null +++ b/components/core/utils/app_constants.py @@ -0,0 +1 @@ +server_secret_key = "123456789" diff --git a/components/core/utils/token_utils.py b/components/core/utils/token_utils.py new file mode 100644 index 00000000..80147937 --- /dev/null +++ b/components/core/utils/token_utils.py @@ -0,0 +1,12 @@ +from flask import g +from Auth import verify_auth_token, generate_auth_token +from utils.app_constants import server_secret_key + + +def token_validator(token): + user = verify_auth_token(token, server_secret_key) + if user is not None: + g.user = user + token = generate_auth_token(user, server_secret_key) + return token + return None From f0cd350ccd6850fc8d1b3861f7fa84e22a189d2d Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Mon, 6 Aug 2018 01:40:11 +0530 Subject: [PATCH 2/9] Implemented file sharing system similar to google drive Signed-off-by: Nirmal Sarswat --- components/core/file_sender/sender.py | 13 +- ui/src/app/completed/controllers/TableCtrl.js | 112 ++++++++++++++++-- ui/src/app/views/table.html | 13 +- 3 files changed, 126 insertions(+), 12 deletions(-) diff --git a/components/core/file_sender/sender.py b/components/core/file_sender/sender.py index 5688866b..18744a2c 100644 --- a/components/core/file_sender/sender.py +++ b/components/core/file_sender/sender.py @@ -8,7 +8,12 @@ def send_file_from_path(): - token = token_validator(request.args['token']) + print("I got the download request man") + token = None + if request.args.get('share') is not None: + token = 'sample-token-for-sharing-feature' + if token is None: + token = token_validator(request.headers['token']) if token is not None: try: gid = request.args.get('gid') @@ -56,7 +61,11 @@ def file_name_formatter(file_name): def start_compression(): - token = token_validator(request.headers['token']) + token = None + if request.args.get('share') is not None: + token = 'sample-token-for-sharing-feature' + if token is None: + token = token_validator(request.headers['token']) if token is not None: gid_list = request.get_json()['gid'] # list of file identifiers to compress gid_list.sort() diff --git a/ui/src/app/completed/controllers/TableCtrl.js b/ui/src/app/completed/controllers/TableCtrl.js index 6b487a26..931db98b 100755 --- a/ui/src/app/completed/controllers/TableCtrl.js +++ b/ui/src/app/completed/controllers/TableCtrl.js @@ -2,12 +2,23 @@ 'use strict'; angular .module('app') - .controller('TableCtrl', [ '$scope', '$mdToast','BassaUrl', 'ToastService', 'TableService', 'UtilityService', TableCtrl]); + .controller('TableCtrl', [ '$scope', '$mdToast', '$mdDialog','BassaUrl', 'ToastService', 'TableService', 'UtilityService', TableCtrl]); - function TableCtrl($scope, $mdToast,BassaUrl, ToastService, TableService, UtilityService) { + function TableCtrl($scope, $mdToast, $mdDialog, BassaUrl, ToastService, TableService, UtilityService) { $scope.downloads = []; $scope.isGridVisible = false; $scope.zipProcessCounter = 0; + $scope.isShowingActions = false; + $scope.checkedFileArray = []; + $scope.shareLink = BassaUrl; + $scope.isShowingCheckbox = false; + let progressDialog = { + controller: DialogController, + template: '', // later change it to a template URL + parent: angular.element(document.body), + clickOutsideToClose: false, + locals : {} + }; $scope.zipToast = $mdToast.simple() .content('Zipping Files') @@ -40,6 +51,11 @@ }; $scope.compressFiles = function(listOfGid){ TableService.startCompression(listOfGid).then(function (response) { + $mdToast.show($scope.zipToast).then(function (toastResponse) { + if(toastResponse === 'ok'){ + ToastService.showToast('Download will start in a while'); + } + }); if(response.data['process_id'] != null) { $scope.zipProcessCounter++; if(response.data['progress'] === 1){ @@ -49,17 +65,99 @@ compressionProgressHandler(response.data['process_id']); }else{ ToastService.showToast('Oops! Something went wrong fetching data'); - return; - } - $mdToast.show($scope.zipToast).then(function (toastResponse) { - if(toastResponse === 'ok'){ - ToastService.showToast('Download will start in a while'); } + }, function(error){ + ToastService.showToast('Oops! Something went wrong fetching data'); }); + }; + $scope.generateSharingLink = function(){ + if($scope.checkedFileArray.length === 0){ + ToastService.showToast("Please checkbox some files to share"); + return; + } + + TableService.startCompression($scope.checkedFileArray).then(function (response) { + $mdDialog.show(progressDialog); + if(response.data['process_id'] != null) { + $scope.shareLink = BassaUrl; + $scope.shareLink += "/api/file?gid="+response.data['process_id']+"&share=true"; + $mdDialog.hide(progressDialog); + progressDialog.locals = { + params:[$scope.shareLink] + }; + progressDialog.template = '
' + + '
'+ + '
'+ + 'Copy it'+ + 'Close'+ + '
'+ + '
'; + $mdDialog.show(progressDialog); + // FIXME :: we can either give the link after it gets compressed, which might be a slow process + }else{ + ToastService.showToast('Oops! Something went wrong fetching data'); + } }, function(error){ ToastService.showToast('Oops! Something went wrong fetching data'); }); }; + function DialogController($scope, $mdDialog, params){ + $scope.copyText = function () { + const tmpElement = document.createElement('textarea'); + tmpElement.value = params[0]; // share link + document.body.appendChild(tmpElement); + tmpElement.select(); + document.execCommand('copy'); + document.body.removeChild(tmpElement); + $scope.closeDialog(); + }; + $scope.closeDialog = function () { + $mdDialog.hide(progressDialog); + resetVariables(); + }; + function resetVariables() { + progressDialog = { + controller: DialogController, + template: '', // later change it to a template URL + parent: angular.element(document.body), + clickOutsideToClose: false, + locals : {} + }; + } + } + $scope.deselectAll = function(){ + $scope.isShowingActions = false; + angular.forEach($scope.downloads, function (item) { + item.checked = false; + }); + $scope.checkedFileArray = []; // using initialization technique instead of popping out + }; + $scope.selectAll = function(){ + $scope.checkedFileArray = []; + $scope.isShowingActions = true; + angular.forEach($scope.downloads, function (item) { + item.checked = true; + $scope.checkedFileArray.push(item.gid); + }); + }; + $scope.onFileItemClick = function () { + $scope.isShowingCheckbox = true; + if($scope.checkedFileArray.length === 0) { + $scope.isShowingActions = false; + }else{ + $scope.isShowingActions = true; + } + }; + $scope.selectThisItem = function (item) { + if(item.checked){ + $scope.checkedFileArray.push(item.gid); + }else{ + $scope.checkedFileArray.pop(item.gid); + if($scope.checkedFileArray.length === 0){ + $scope.isShowingActions = false; + } + } + }; var compressionProgressHandler = function(downloadGid){ var processInterval = setInterval(function () { TableService.compressionProgress(downloadGid).then(function (response){ diff --git a/ui/src/app/views/table.html b/ui/src/app/views/table.html index 74aac223..9d76daf4 100755 --- a/ui/src/app/views/table.html +++ b/ui/src/app/views/table.html @@ -1,5 +1,10 @@
- {{ isGridVisible ? 'view_list' : 'view_module' }} +
+ {{ isGridVisible ? 'view_list' : 'view_module' }} + share + check_circle_outline + check_circle +
@@ -12,19 +17,20 @@ - + +
{{$index + 1}} {{data.user_name}} {{data.download_name}} {{data.size}}
    -
  • +
  • image caption @@ -35,6 +41,7 @@ +
From 104c572397daa0293fed698c8e7fbfc4048fbd5c Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Mon, 6 Aug 2018 01:44:01 +0530 Subject: [PATCH 3/9] removed print statement Signed-off-by: Nirmal Sarswat --- components/core/file_sender/sender.py | 1 - 1 file changed, 1 deletion(-) diff --git a/components/core/file_sender/sender.py b/components/core/file_sender/sender.py index 18744a2c..7e845e45 100644 --- a/components/core/file_sender/sender.py +++ b/components/core/file_sender/sender.py @@ -8,7 +8,6 @@ def send_file_from_path(): - print("I got the download request man") token = None if request.args.get('share') is not None: token = 'sample-token-for-sharing-feature' From 41b418151f7c759a9b194bfb9186391b6615b782 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Sat, 22 Sep 2018 19:15:48 +0530 Subject: [PATCH 4/9] changing to uppercase --- components/core/utils/app_constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/core/utils/app_constants.py b/components/core/utils/app_constants.py index cd0a360f..9a141878 100644 --- a/components/core/utils/app_constants.py +++ b/components/core/utils/app_constants.py @@ -1 +1 @@ -server_secret_key = "123456789" +SERVER_SECRET_KEY = "123456789" From 65377ed5dcd8217b65d559186c28615c12b3add5 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Sat, 22 Sep 2018 19:16:52 +0530 Subject: [PATCH 5/9] Update token_utils.py --- components/core/utils/token_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/core/utils/token_utils.py b/components/core/utils/token_utils.py index 80147937..92583c18 100644 --- a/components/core/utils/token_utils.py +++ b/components/core/utils/token_utils.py @@ -1,12 +1,13 @@ from flask import g from Auth import verify_auth_token, generate_auth_token -from utils.app_constants import server_secret_key +from utils.app_constants import SERVER_SECRET_KEY + def token_validator(token): - user = verify_auth_token(token, server_secret_key) + user = verify_auth_token(token, SERVER_SECRET_KEY) if user is not None: g.user = user - token = generate_auth_token(user, server_secret_key) + token = generate_auth_token(user, SERVER_SECRET_KEY) return token return None From 64c2b06de4e24f9bc8f790a267c74eee8af20303 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Sat, 22 Sep 2018 19:18:32 +0530 Subject: [PATCH 6/9] Update initializer.py --- components/core/initializer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/core/initializer.py b/components/core/initializer.py index 90733ff1..278d1c61 100644 --- a/components/core/initializer.py +++ b/components/core/initializer.py @@ -4,16 +4,16 @@ from flask_socketio import SocketIO from gevent import monkey -from utils.app_constants import server_secret_key +from utils.app_constants import SERVER_SECRET_KEY monkey.patch_all(ssl=False) server = Flask(__name__) -server.config['SECRET_KEY'] = server_secret_key +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 \ No newline at end of file + verbose = True From a5849e29c6f0008e5502613e2b596325f993a982 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Sat, 22 Sep 2018 19:20:21 +0530 Subject: [PATCH 7/9] Update Download.py --- components/core/routes/Download.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/core/routes/Download.py b/components/core/routes/Download.py index 7d8495f4..7b51485e 100644 --- a/components/core/routes/Download.py +++ b/components/core/routes/Download.py @@ -5,7 +5,7 @@ import json, urllib.request, urllib.error, urllib.parse from multiprocessing import Process from DownloadDaemon import starter -from utils.app_constants import server_secret_key +from utils.app_constants import SERVER_SECRET_KEY from utils.token_utils import token_validator from initializer import socketio @@ -13,7 +13,7 @@ def start(): try: token = request.headers['key'] - if str(token) != server_secret_key: + if str(token) != SERVER_SECRET_KEY: return "{'error':'not authorized'}", 403 global p p = Process(target=starter, args=(socketio,)) @@ -26,7 +26,7 @@ def start(): def kill(): try: token = request.headers['key'] - if str(token) != server_secret_key: + if str(token) != SERVER_SECRET_KEY: return "{'error':'not authorized'}", 403 if p is not None: p.terminate() From bde2126f5d7ab8e59f5d51b8b2b4e256c69c0c62 Mon Sep 17 00:00:00 2001 From: Nirmal Sarswat Date: Sat, 22 Sep 2018 19:20:51 +0530 Subject: [PATCH 8/9] Update User.py --- components/core/routes/User.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/core/routes/User.py b/components/core/routes/User.py index 9b9e958f..ab79d3e7 100644 --- a/components/core/routes/User.py +++ b/components/core/routes/User.py @@ -6,7 +6,7 @@ from DownloadManager import * import _thread from utils.token_utils import token_validator -from utils.app_constants import server_secret_key +from utils.app_constants import SERVER_SECRET_KEY def login(): @@ -15,7 +15,7 @@ def login(): if user_login(userName, password): if check_approved(userName, password): user = get_user(userName) - token = generate_auth_token(user, server_secret_key) + token = generate_auth_token(user, SERVER_SECRET_KEY) resp = Response(response='{"auth":"'+ str(user.auth) + '"}',status=200) resp.headers['token'] = token resp.headers['Access-Control-Expose-Headers'] = 'token' From a55d19d086734a8818b71417c7c21096f0b90400 Mon Sep 17 00:00:00 2001 From: Aakash Bansal Date: Sun, 30 Sep 2018 21:54:19 +0530 Subject: [PATCH 9/9] Add Download input field returns to untouched state when download is added --- ui/src/app/views/dashboard.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/app/views/dashboard.html b/ui/src/app/views/dashboard.html index 7b2e5923..e98092db 100755 --- a/ui/src/app/views/dashboard.html +++ b/ui/src/app/views/dashboard.html @@ -3,7 +3,7 @@ - + add