Island: Rename file_type -> target_os in FileUpload resource

This commit is contained in:
Mike Salvatore 2022-04-26 13:41:16 -04:00
parent 1d938e58f8
commit 55c4f68902
2 changed files with 17 additions and 18 deletions

View File

@ -174,9 +174,9 @@ def init_api_resources(flask_resource_manager: FlaskResourceManager):
)
flask_resource_manager.add_resource(
FileUpload,
"/api/file-upload/<string:file_type>",
"/api/file-upload/<string:file_type>?load=<string:filename>",
"/api/file-upload/<string:file_type>?restore=<string:filename>",
"/api/file-upload/<string:target_os>",
"/api/file-upload/<string:target_os>?load=<string:filename>",
"/api/file-upload/<string:target_os>?restore=<string:filename>",
)
flask_resource_manager.add_resource(

View File

@ -29,21 +29,20 @@ class FileUpload(flask_restful.Resource):
self._file_storage_service = file_storage_service
# TODO: Fix references/coupling to filepond
# TODO: Replace "file_type" with "target_os" or similar
# TODO: Add comment explaining why this is basically a duplicate of the endpoint in the
# PBAFileDownload resource.
@jwt_required
def get(self, file_type):
def get(self, target_os):
"""
Sends file to filepond
:param file_type: Type indicates which file to send, linux or windows
:param target_os: Indicates which file to send, linux or windows
:return: Returns file contents
"""
if self._is_pba_file_type_supported(file_type):
if self._is_target_os_supported(target_os):
return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain")
# Verify that file_name is indeed a file from config
if file_type == LINUX_PBA_TYPE:
if target_os == LINUX_PBA_TYPE:
# TODO: Make these paths Tuples so we don't need to copy them
filename = ConfigService.get_config_value(copy.deepcopy(PBA_LINUX_FILENAME_PATH))
else:
@ -60,20 +59,20 @@ class FileUpload(flask_restful.Resource):
return make_response({"error": error_msg}, 404)
@jwt_required
def post(self, file_type):
def post(self, target_os):
"""
Receives user's uploaded file from filepond
:param file_type: Type indicates which file was received, linux or windows
:param target_os: Type indicates which file was received, linux or windows
:return: Returns flask response object with uploaded file's filename
"""
if self._is_pba_file_type_supported(file_type):
if self._is_target_os_supported(target_os):
return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain")
filename = self._upload_pba_file(
# TODO: This "filepond" string can be changed to be more generic in the `react-filepond`
# component.
request.files["filepond"],
(file_type == LINUX_PBA_TYPE),
(target_os == LINUX_PBA_TYPE),
)
response = Response(response=filename, status=200, mimetype="text/plain")
@ -96,17 +95,17 @@ class FileUpload(flask_restful.Resource):
return filename
@jwt_required
def delete(self, file_type):
def delete(self, target_os):
"""
Deletes file that has been deleted on the front end
:param file_type: Type indicates which file was deleted, linux of windows
:param target_os: Type indicates which file was deleted, linux of windows
:return: Empty response
"""
if self._is_pba_file_type_supported(file_type):
if self._is_target_os_supported(target_os):
return Response(status=HTTPStatus.UNPROCESSABLE_ENTITY, mimetype="text/plain")
filename_path = (
PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH
PBA_LINUX_FILENAME_PATH if target_os == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH
)
filename = ConfigService.get_config_value(filename_path)
if filename:
@ -116,5 +115,5 @@ class FileUpload(flask_restful.Resource):
return make_response({}, 200)
@staticmethod
def _is_pba_file_type_supported(file_type: str) -> bool:
return file_type not in {LINUX_PBA_TYPE, WINDOWS_PBA_TYPE}
def _is_target_os_supported(target_os: str) -> bool:
return target_os not in {LINUX_PBA_TYPE, WINDOWS_PBA_TYPE}