Bugfix in file upload for PBAs (nonexistent directory)
This commit is contained in:
parent
40aca91b28
commit
1e8e9a7d41
|
@ -21,6 +21,9 @@ class FileUpload(flask_restful.Resource):
|
|||
"""
|
||||
File upload endpoint used to exchange files with filepond component on the front-end
|
||||
"""
|
||||
def __init__(self):
|
||||
# Create all directories on the way if they don't exist
|
||||
UPLOADS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@jwt_required()
|
||||
def get(self, file_type):
|
||||
|
@ -59,7 +62,7 @@ class FileUpload(flask_restful.Resource):
|
|||
"""
|
||||
filename_path = PBA_LINUX_FILENAME_PATH if file_type == 'PBAlinux' else PBA_WINDOWS_FILENAME_PATH
|
||||
filename = ConfigService.get_config_value(filename_path)
|
||||
file_path = os.path.join(UPLOADS_DIR, filename)
|
||||
file_path = UPLOADS_DIR.joinpath(filename)
|
||||
try:
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
@ -78,7 +81,7 @@ class FileUpload(flask_restful.Resource):
|
|||
:return: filename string
|
||||
"""
|
||||
filename = secure_filename(request_.files['filepond'].filename)
|
||||
file_path = os.path.join(UPLOADS_DIR, filename)
|
||||
request_.files['filepond'].save(file_path)
|
||||
file_path = UPLOADS_DIR.joinpath(filename).absolute()
|
||||
request_.files['filepond'].save(str(file_path))
|
||||
ConfigService.set_config_value((PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename)
|
||||
return filename
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import monkey_island.cc.services.config
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
__author__ = "VakarisZ"
|
||||
|
||||
|
@ -9,7 +10,7 @@ logger = logging.getLogger(__name__)
|
|||
# Where to find file names in config
|
||||
PBA_WINDOWS_FILENAME_PATH = ['monkey', 'behaviour', 'PBA_windows_filename']
|
||||
PBA_LINUX_FILENAME_PATH = ['monkey', 'behaviour', 'PBA_linux_filename']
|
||||
UPLOADS_DIR = 'monkey_island/cc/userUploads'
|
||||
UPLOADS_DIR = Path('monkey_island', 'cc', 'userUploads')
|
||||
|
||||
|
||||
def remove_PBA_files():
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue