diff --git a/.travis.yml b/.travis.yml index 04249159..4290ba94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,24 +6,22 @@ sudo: required services: - docker -before_install: - - | - if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(.md)|(.png)|(.)|^(LICENSE)|^(docs)|^(robots.txt)|^(package-list-yum)|^(package-list-pacman)|^(package-list-dnf)|^(package-list-brew)|^(package-list-aptget)|^(humans.txt)|^(docker-compose.yml)|^(docker-compose.dev.yml)|^(bassa)|^(.gitignore)|^(.gitattributes)|^(bassa-ui.yaml)|^(bassa-ingress.yaml)|^(bassa-api.yaml)|^(deploy_rds.sh)|^(rds-dev.json)|^(template.json)|^(setup-mysql.sh)|^(setup-database.sh)|^(create-schema.sh)|^(Bassa.sql)' - then - echo "Files changed not related to dockerfile, therefore travis build ends" - exit - fi script: - - docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-ui ui - - docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa components/core + - docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-prod-ui ui + - docker build -f ui/Dockerfile.dev --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-dev-ui ui + - docker build -f components/core/Dockerfile.prod --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-prod-server components/core + - docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-dev-server components/core + - docker build --build-arg VCS_REF=`git rev-parse --short HEAD` --build-arg BUILD_DATE=`date -u +”%Y-%m-%dT%H:%M:%SZ”` -t scoreucsc/bassa-aria2c components/aria2c + after_success: - - if [ "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_PULL_REQUEST" == "false" ]; then + - if [ "$TRAVIS_BRANCH" == "develop" -a "$TRAVIS_PULL_REQUEST" == "true" ]; then docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"; - docker push scoreucsc/bassa; - curl -X POST 'https://hooks.microbadger.com/images/scoreucsc/bassa/Wbi5zehDMooS3ri2bgC8LETGGuQ='; - docker push scoreucsc/bassa-ui; - curl -X POST 'https://hooks.microbadger.com/images/scoreucsc/bassa-ui/et6pa2aJq-tEvwFoW-PL8ixNxr0='; + docker push scoreucsc/bassa-prod-ui; + docker push scoreucsc/bassa-dev-ui; + docker push scoreucsc/bassa-prod-server; + docker push scoreucsc/bassa-dev-server + docker push scoreucsc/bassa-aria2c; fi diff --git a/components/aria2c/Dockerfile b/components/aria2c/Dockerfile index 15f1c065..f2da66fa 100644 --- a/components/aria2c/Dockerfile +++ b/components/aria2c/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:edge +FROM alpine:3 # Defining dockerfile maintainer MAINTAINER SCoRe Lab Community @@ -15,13 +15,13 @@ RUN apk update && \ EXPOSE 6800 # Volume for storing the downloaded data -VOLUME [ "/data" ] +VOLUME [ "/downloads" ] # Changing the current directory to data so that the files get downloaded there -WORKDIR /data +WORKDIR /downloads # Starting the Aria2c RPC server -CMD ["aria2c", "--enable-rpc", "--rpc-listen-all"] +CMD ["aria2c", "--enable-rpc=true", "--rpc-listen-all", "--no-conf=true", "--disable-ipv6", "--console-log-level=debug"] # Labels for dockerfile information LABEL scorelab.bassa.name="Aria2c RPC server" \ diff --git a/components/core/DownloadDaemon.py b/components/core/DownloadDaemon.py index 01da9379..9efa0339 100644 --- a/components/core/DownloadDaemon.py +++ b/components/core/DownloadDaemon.py @@ -7,8 +7,8 @@ from EMail import send_mail from DiskMan import * from ConfReader import get_conf_reader -from MinioHandler import * import logging +from MinioHandler import * import websocket import sys @@ -86,6 +86,9 @@ def worker(self): data = json.loads(message) print(threading.current_thread().name,data) print ("TOP LEVEL DATA", data) + if 'error' in data: + logging.error("Aria2c error: %s", data['error']) + return if 'id' in data and data['id'] == "act": toBeDownloaded = get_to_download() if toBeDownloaded: @@ -178,6 +181,7 @@ def add_uri(ws, download): def get_status(ws, id=None, gid=None): if id: gid = get_gid_from_id(id) + gid = str(gid) msg = JSONer("stat", 'aria2.tellStatus', [gid, ['gid', 'files']]) print ("Getting status") ws.send(msg) @@ -236,7 +240,7 @@ def on_message(ws, message): messageQueue.put(message) def on_error(ws, error): - print(error) + logging.error(error) def on_close(ws): @@ -252,6 +256,7 @@ def starter(socket): sc = socket remove_files(conf['max_age'], conf['min_rating']) folder_size=get_size(conf['down_folder']) + logging.info("SERVER: folder_size: %d", folder_size) websocket.enableTrace(False) ws = websocket.WebSocketApp(conf['aria_server'], on_message=on_message, @@ -268,4 +273,3 @@ def starter(socket): - diff --git a/components/core/DownloadManager.py b/components/core/DownloadManager.py index fbb20d23..e3ef997a 100644 --- a/components/core/DownloadManager.py +++ b/components/core/DownloadManager.py @@ -3,13 +3,14 @@ import time import sys import sqlalchemy.pool as pool +import logging verbose = False if len(sys.argv) == 2 and sys.argv[1] == '-v': verbose = True -threadpool = pool.QueuePool(get_db_con, max_overflow=10, pool_size=20) +threadpool = pool.QueuePool(get_db_con, max_overflow=10, pool_size=0) def add_download(download): @@ -23,12 +24,12 @@ def add_download(download): sql = "INSERT into download(link, user_name, added_time, download_name) VALUES(%s, %s, %s, %s);" try: cursor.execute(sql, (download.link, download.userName, int(time.time()), download_name)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - # Shows error thrown up by database - print(e) - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -42,14 +43,19 @@ def remove_download(id, userName): try: cursor.execute(sql1, [str(id)]) data = cursor.fetchone() + cursor.close() if data[0] != Status.DEFAULT and data[0] != Status.ERROR: db.commit() + db.close() return "Download started. Entry cannot be deleted." + cursor = db.cursor() cursor.execute(sql, [str(id), userName]) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -66,11 +72,13 @@ def rate_download(id, userName, rate): cursor.execute(sql1, (rate, id, userName)) if cursor.rowcount == 0: cursor.execute(sql, (userName, id, rate)) + cursor.close() db.commit() + db.close() update_rate(id) except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -85,10 +93,12 @@ def update_rate(id): cursor.execute(sql1, id) data = cursor.fetchone() cursor.execute(sql, (data[0], id)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -105,7 +115,7 @@ def get_downloads_user(userName, limit): db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -121,7 +131,7 @@ def get_downloads(limit): db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -138,10 +148,12 @@ def update_status_gid(gid, status, completed=False): cursor.execute(sql, (status, int(time.time()), gid)) else: cursor.execute(sql, (status, gid)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -153,10 +165,12 @@ def set_gid(id, gid): sql = "UPDATE download SET gid='%s' WHERE id=%s;" % (gid, id) try: cursor.execute(sql) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -168,10 +182,12 @@ def set_name(gid, name): sql = "UPDATE download SET download_name=%s WHERE gid=%s ;" try: cursor.execute(sql, (name, gid)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -183,10 +199,12 @@ def set_size(gid, size): sql = "UPDATE download SET size=%s WHERE gid=%s ;" try: cursor.execute(sql, (size, gid)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -202,11 +220,13 @@ def get_to_download(): if verbose: print("zero count") return None results = cursor.fetchall() + cursor.close() + db.close() if verbose: print("LIST", results) downloads = [Download(result['link'], result['user_name'], result['id']) for result in results] return downloads except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -217,10 +237,12 @@ def set_path(gid, path): sql = "UPDATE download SET path=%s WHERE gid=%s ;" try: cursor.execute(sql, (path, gid)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -235,11 +257,12 @@ def get_download_path(id): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() path = results['path'] db.close() return path except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -253,11 +276,12 @@ def get_download_email(gid): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() path = results['email'] db.close() return path except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -270,12 +294,13 @@ def get_to_delete(time, rate): try: cursor.execute(sql, (time, rate)) results = cursor.fetchall() + cursor.close() db.close() if verbose: print("Time", time, "Rate", rate) if verbose: print("results", results) return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -286,10 +311,12 @@ def set_delete_status(path): sql = "UPDATE download SET status=2 WHERE path='%s' ;" % path try: cursor.execute(sql) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -304,12 +331,13 @@ def get_download_status(id): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() print('results') status = results['status'] db.close() return status except MySQLdb.Error as e: - return e[1] + raise return "db connection error" @@ -323,11 +351,12 @@ def get_id_from_gid(gid): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() status = results['id'] db.close() return status except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -341,11 +370,12 @@ def get_username_from_gid(gid): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() status = results['user_name'] db.close() return status except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -359,11 +389,12 @@ def get_gid_from_id(id): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() gid = results['gid'] db.close() return gid except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -377,11 +408,12 @@ def get_download_name_from_id(id): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() download_name = results['download_name'] db.close() return download_name except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -396,12 +428,12 @@ def set_compression_progress(comp_id, status, **kwargs): 'completed_time'], comp_id) try: cursor.execute(sql, ) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - # Shows error thrown up by database - print(e) - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -416,11 +448,12 @@ def get_compression_progress(comp_id): if cursor.rowcount == 0: return None results = cursor.fetchone() + cursor.close() status = results['progress'] db.close() return status except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" @@ -433,12 +466,12 @@ def insert_compression_process(comp_id, start_time, completed_time, is_deleted): comp_id, start_time, completed_time, is_deleted) try: cursor.execute(sql, ) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - # Shows error thrown up by database - print(e) - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return 0 return "db connection error" @@ -451,6 +484,7 @@ def update_minio_indexes(file_name, file_path, gid, completedLength, username, d cursor.execute(sql, (download_id, gid, username, file_name, completedLength, file_path)) db.commit() cursor.close() + db.close() except MySQLdb.Error as e: db.rollback() # Shows error thrown up by database @@ -468,10 +502,11 @@ def get_file_name(id): return None results = cursor.fetchone() print(results) + cursor.close() file_name = results['mfile_name'] db.close() return file_name except MySQLdb.Error as e: print(e) - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" diff --git a/components/core/Starter.py b/components/core/Starter.py index 36c7252d..1440fbd3 100644 --- a/components/core/Starter.py +++ b/components/core/Starter.py @@ -1,6 +1,6 @@ import urllib.request, urllib.error, urllib.parse -req = urllib.request.Request('http://localhost:5000/download/start') +req = urllib.request.Request('http://localhost:5000/api/download/start') req.add_header('key', '123456789') resp = urllib.request.urlopen(req) content = resp.read() diff --git a/components/core/UserManager.py b/components/core/UserManager.py index 74d5fe0e..465c376e 100644 --- a/components/core/UserManager.py +++ b/components/core/UserManager.py @@ -2,10 +2,11 @@ from DBCon import * from ConfReader import get_conf_reader import sqlalchemy.pool as pool +import logging conf = get_conf_reader("dl.conf") -threadpool = pool.QueuePool(get_db_con, max_overflow=10, pool_size=20) +threadpool = pool.QueuePool(get_db_con, max_overflow=10, pool_size=0) def user_login(username, password): db = threadpool.connect() @@ -14,6 +15,7 @@ def user_login(username, password): sql = "SELECT * FROM user WHERE user_name=%s AND password=MD5(%s) AND blocked=0;" cursor.execute(sql, (username, password)) data = cursor.fetchone() + cursor.close() db.close() if data == None: return False @@ -27,6 +29,7 @@ def check_approved(username, password): sql = "SELECT * FROM user WHERE user_name=%s AND password=MD5(%s) AND approved=1;" cursor.execute(sql, (username, password)) data = cursor.fetchone() + cursor.close() db.close() if data == None: return False @@ -40,6 +43,7 @@ def check_user_name(username): sql = "SELECT * FROM user WHERE user_name=%s;" cursor.execute(sql, (username)) data = cursor.fetchone() + cursor.close() db.close() if data == None: return False @@ -54,6 +58,7 @@ def get_user(username): sql = "SELECT * FROM user WHERE user_name='%s' and blocked=0;" % username cursor.execute(sql) data = cursor.fetchone() + cursor.close() db.close() if data == None: return None @@ -68,10 +73,12 @@ def add_user(user): sql = "INSERT into user VALUES(%s, MD5(%s), %s, %s, 0, 0);" try: cursor.execute(sql, (user.userName, user.password, user.auth, user.email)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -82,7 +89,9 @@ def add_regular_user(user): sql = "INSERT into user VALUES(%s, MD5(%s), %s, %s, 0, 0);" try: cursor.execute(sql, (user.userName, user.password, user.auth, user.email)) + cursor.close() db.commit() + db.close() except MySQLdb.IntegrityError: db.rollback() return "username taken" @@ -96,10 +105,12 @@ def remove_user(username): sql = "DELETE from user WHERE user_name=%s;" try: cursor.execute(sql, (username)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -111,10 +122,12 @@ def update_user(user, username): sql = "UPDATE user SET user_name=%s, auth=%s, email=%s WHERE user_name=%s;" try: cursor.execute(sql, (user.userName, user.auth, user.email, username)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -126,10 +139,11 @@ def get_users(): try: cursor.execute(sql) results = cursor.fetchall() + cursor.close() db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" def get_blocked_users(): @@ -140,10 +154,11 @@ def get_blocked_users(): try: cursor.execute(sql) results = cursor.fetchall() + cursor.close() db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" def block_user(username): @@ -153,10 +168,12 @@ def block_user(username): sql = "UPDATE user SET blocked=%s WHERE user_name=%s;" try: cursor.execute(sql, (1, username)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -167,10 +184,12 @@ def unblock_user(username): sql = "UPDATE user SET blocked=%s WHERE user_name=%s;" try: cursor.execute(sql, (0, username)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -182,10 +201,11 @@ def get_signup_requests(): try: cursor.execute(sql) results = cursor.fetchall() + cursor.close() db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" def approve_user(username): @@ -195,10 +215,12 @@ def approve_user(username): sql = "UPDATE user SET approved=%s WHERE user_name=%s;" try: cursor.execute(sql, (1, username)) + cursor.close() db.commit() + db.close() except MySQLdb.Error as e: db.rollback() - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "success" return "db connection error" @@ -211,10 +233,11 @@ def get_heavy_users(): try: cursor.execute(sql) results = cursor.fetchall() + cursor.close() db.close() return results except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" def check_if_bandwidth_exceeded(username): @@ -226,6 +249,8 @@ def check_if_bandwidth_exceeded(username): try: cursor.execute(sql, (MONTH, username)) result = cursor.fetchone() + cursor.close() + db.close() if result['sum'] == None: return False elif result['sum'] > conf['max_bandwidth']: @@ -234,5 +259,5 @@ def check_if_bandwidth_exceeded(username): return False return result except MySQLdb.Error as e: - return e[1] + logging.error("Error %d: %s", e.args[0], e.args[1]) return "db connection error" diff --git a/components/core/dl.conf b/components/core/dl.conf index a4737565..a576b79c 100644 --- a/components/core/dl.conf +++ b/components/core/dl.conf @@ -1 +1 @@ -{"max_downloads": 2, "down_folder": "../../downloads", "size_limit":100000, "max_age":1, "min_rating":3, "max_bandwidth": 300000, "aria_server": "ws://localhost:6800/jsonrpc", "tmp_folder": "/tmp/bassa/"} +{"max_downloads": 2, "down_folder": "../../downloads", "size_limit":1000000000000, "max_age":1, "min_rating":3, "max_bandwidth": 1000000000000, "aria_server": "ws://aria2c:6800/jsonrpc", "tmp_folder": "/tmp/bassa/"} diff --git a/components/core/file_sender/compression_handler.py b/components/core/file_sender/compression_handler.py index 57638f1e..8ff1754a 100644 --- a/components/core/file_sender/compression_handler.py +++ b/components/core/file_sender/compression_handler.py @@ -14,10 +14,11 @@ def compress(file_list, file_name): timestamp = time.time() status = insert_compression_process(comp_id=file_name, start_time=timestamp, completed_time=timestamp, is_deleted=0) zip_path = get_zip_path(file_name) - zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) + zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_STORED) set_compression_progress(comp_id=file_name, status=status, completed_time=timestamp) for file in file_list: if os.path.exists(file): + logging.info("file: %s", file) zip_file.write(file, basename(file)) zip_file.close() logging.info('Compression of files is done, written to following file {0}'.format(zip_path)) @@ -55,7 +56,9 @@ def file_name_formatter(file_name): if __name__ == "__main__": logging.basicConfig(filename="./debug-server.log", level=logging.DEBUG) gid_list = sys.argv + logging.info("before pop %s", gid_list) gid_list.pop(0) # remove file name as an argument + logging.info("after pop %s", gid_list) gid_list.sort() file_path_list = [] ugid_of_compressed_file = '' @@ -64,4 +67,5 @@ def file_name_formatter(file_name): id = get_id_from_gid(elem) download_path = get_download_path(id) file_path_list.append(download_path) + logging.info(file_path_list) compress(file_path_list, ugid_of_compressed_file) diff --git a/components/core/routes/Download.py b/components/core/routes/Download.py index 2debdace..756cc555 100644 --- a/components/core/routes/Download.py +++ b/components/core/routes/Download.py @@ -13,14 +13,23 @@ conf = get_conf_reader("dl.conf") +processes = [] def start(): try: token = request.headers['key'] if str(token) != SERVER_SECRET_KEY: return "{'error':'not authorized'}", 403 - global p + if len(processes) != 0: + p = processes[0] + processes.clear() + p.terminate() + p.join() + jsonreq = json.dumps({'jsonrpc': '2.0', 'id': 'qwer', 'method': 'aria2.pauseAll'}) + jsonreq = jsonreq.encode('ascii') + urllib.request.urlopen(conf['aria_server'], jsonreq) p = Process(target=starter, args=(socketio,)) + processes.append(p) p.start() return '{"status":"' + str(p.pid) + '"}' except Exception as e: diff --git a/components/core/routes/views/Download_endpoints.py b/components/core/routes/views/Download_endpoints.py index b5d30f2e..ab76bc39 100644 --- a/components/core/routes/views/Download_endpoints.py +++ b/components/core/routes/views/Download_endpoints.py @@ -3,11 +3,11 @@ downloadprint = Blueprint("download", __name__) -downloadprint.add_url_rule(rule='/download/start', +downloadprint.add_url_rule(rule='/api/download/start', endpoint='start', view_func=start) -downloadprint.add_url_rule(rule='/download/kill', +downloadprint.add_url_rule(rule='/api/download/kill', endpoint='kill', view_func=kill) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 695ebc4f..15bda694 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -34,7 +34,7 @@ services: ports: - 6800:6800 volumes: - - ./downloads:/data + - ./downloads:/downloads restart: always db: diff --git a/docker-compose.yml b/docker-compose.yml index 4b7e6d6d..b9e2f088 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ services: ports: - 6800:6800 volumes: - - ./downloads:/data + - ./downloads:/downloads restart: always db: diff --git a/downloads/data.txt b/downloads/data.txt deleted file mode 100644 index 033229c4..00000000 --- a/downloads/data.txt +++ /dev/null @@ -1,2 +0,0 @@ -This folder contains downloaded data from Aria2c -which is mapped to both Bassa API container and Aria2c RPC server \ No newline at end of file diff --git a/ui/src/app/completed/controllers/TableCtrl.js b/ui/src/app/completed/controllers/TableCtrl.js index 1b9b0ce8..65a274f5 100755 --- a/ui/src/app/completed/controllers/TableCtrl.js +++ b/ui/src/app/completed/controllers/TableCtrl.js @@ -44,7 +44,7 @@ $mdToast.hide($scope.zipToast); } if(token) { - window.location.href = BassaUrl + '/api/file?gid=' + downloadGID + "&token=" + token; + window.location.href = BassaUrl + '/api/file?gid=' + downloadGID + "&share=" + token; }else{ ToastService.showToast("Unable to process your download request") } diff --git a/ui/src/app/completed/services/tableService.js b/ui/src/app/completed/services/tableService.js index a5f66b07..72e6e0ab 100755 --- a/ui/src/app/completed/services/tableService.js +++ b/ui/src/app/completed/services/tableService.js @@ -1,12 +1,12 @@ -(function(){ +(function () { 'use strict'; angular.module('app') .service('TableService', ['$http', 'BassaUrl', TableService]); - function TableService($http, BassaUrl){ + function TableService($http, BassaUrl) { - var getCompletedDownloads = function() { + var getCompletedDownloads = function () { return $http({ method: 'GET', url: BassaUrl + '/api/downloads/1' @@ -14,30 +14,30 @@ }; var startCompression = function (gids) { return $http({ - method: 'POST', - url : BassaUrl + '/api/compress', - data : {'gid' : gids} + method: 'POST', + url: BassaUrl + '/api/compress', + data: { 'gid': gids }, }) }; var compressionProgress = function (progressId) { return $http({ - method: 'GET', - url : BassaUrl + '/api/compression-progress?gid=' + progressId + method: 'GET', + url: BassaUrl + '/api/compression-progress?gid=' + progressId }) }; - var downloadFromMinio = function(downloadId) { + var downloadFromMinio = function (downloadId) { return $http({ method: 'GET', - url : BassaUrl + '/api/file_from_minio/' + downloadId + url: BassaUrl + '/api/file_from_minio/' + downloadId }) }; return { - getCompletedDownloads : getCompletedDownloads, - startCompression : startCompression, - compressionProgress : compressionProgress, - downloadFromMinio : downloadFromMinio + getCompletedDownloads: getCompletedDownloads, + startCompression: startCompression, + compressionProgress: compressionProgress, + downloadFromMinio: downloadFromMinio }; } })(); diff --git a/ui/src/app/index.js b/ui/src/app/index.js index 12529972..158f98a3 100755 --- a/ui/src/app/index.js +++ b/ui/src/app/index.js @@ -1,10 +1,10 @@ 'use strict'; -import { config } from "../../config"; +// import { constants } from "./config"; angular.module('bassa', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ui.router', 'ngMaterial', 'nvd3', 'app']) - .value('BassaUrl', config.API_URL) + .value('BassaUrl', "http://localhost:5000") .config(function ($stateProvider, $httpProvider, $urlRouterProvider, $mdThemingProvider, $mdIconProvider, $qProvider) { diff --git a/ui/src/app/signup/controllers/SignupCtrl.js b/ui/src/app/signup/controllers/SignupCtrl.js index 6f31f615..ce466ad6 100755 --- a/ui/src/app/signup/controllers/SignupCtrl.js +++ b/ui/src/app/signup/controllers/SignupCtrl.js @@ -13,7 +13,6 @@ }; $scope.incorrectCredentials = false; - $scope.errorMsg = ''; var validate = function(obj) { for (var key in obj) { @@ -47,42 +46,6 @@ ToastService.showToast('Please ensure entered details are correct'); } }; - - - function passwordValid() { - $scope.loginForm.password.$valid = true; - $scope.loginForm.password.$dirty = false; - $scope.loginForm.password.$invalid = false; - } - function passwordInValid() { - $scope.loginForm.password.$valid = false; - $scope.loginForm.password.$invalid = true; - $scope.loginForm.password.$dirty = true; - } - - $scope.validatePwd = () => { - const lowerCaseLetters = /[a-z]/g; - const upperCaseLetters = /[A-Z]/g; - const numbers = /[0-9]/g; - if (typeof $scope.user.password !== 'undefined') { - if ($scope.user.password.length < 8) { - passwordInValid(); - $scope.errorMsg = 'Password must contains Minimum 8 characters'; - } else if (!$scope.user.password.match(upperCaseLetters)) { - passwordInValid(); - $scope.errorMsg = 'Password must contains a uppercase letter'; - } else if (!$scope.user.password.match(lowerCaseLetters)) { - passwordInValid(); - $scope.errorMsg = 'Password must contains a lowercase letter'; - } else if (!$scope.user.password.match(numbers)) { - passwordInValid(); - $scope.errorMsg = 'Password must contains a number'; - } else { - passwordValid(); - $scope.errorMsg = ''; - } - } - }; } })(); diff --git a/ui/src/app/views/table.html b/ui/src/app/views/table.html index 25e9e353..6a14baaa 100755 --- a/ui/src/app/views/table.html +++ b/ui/src/app/views/table.html @@ -5,7 +5,7 @@ check_circle_outline check_circle - +
@@ -23,7 +23,7 @@ - + @@ -37,7 +37,7 @@

There are no completed downloads yet!

#{{data.download_name}} {{data.size}}