From 3f087c5d83063121bcb383f9e643ce73f413a4b3 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Fri, 8 Jan 2021 19:11:18 +0100 Subject: [PATCH] Remove unneeded update function in storages --- middleware/app_be/services/dropboxservice.py | 30 ++------------------ middleware/app_be/services/minioservice.py | 29 ------------------- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/middleware/app_be/services/dropboxservice.py b/middleware/app_be/services/dropboxservice.py index b4f5f45..1abbf72 100644 --- a/middleware/app_be/services/dropboxservice.py +++ b/middleware/app_be/services/dropboxservice.py @@ -55,32 +55,6 @@ class DropboxService(StorageServiceInterface): print("Error downloading file from dropbox") return file_bytes - @staticmethod - def update_file(filename: str, file: bytes) -> bool: - """Update a file on the dropbox storage. - - Increments a counter until we get to the newest version, then - create the file with the newest version + 1. - :param filename: filename of the file - :param file: bytes representation of the file - :return: Whether file was successfully uploaded - """ - identifier = filename.strip('.jpg') - print("DropboxService: Trying to update file with identifier ", identifier) - i = 0 - while True: - try: - dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN) - print("DropboxService: Checking if version {} exists".format(identifier + '_' + str(i) + '.jpg')) - dbx.files_get_metadata(identifier + '_' + str(i) + '.jpg') - i = i + 1 - except: - print("DropboxService: Version {} exists".format(identifier + '_' + str(i) + '.jpg')) - break - - print("DropboxService: Creating new version {}".format(identifier + '_' + str(i) + '.jpg')) - return DropboxService.create_file(identifier + '_' + str(i) + '.jpg', file) - @staticmethod def move_file(identifier_from: str, identifier_to: str) -> bool: """Move/Rename a file on the dropbox storage. @@ -89,7 +63,8 @@ class DropboxService(StorageServiceInterface): :param identifier_to: Location the file should be moved to :return True on success, False otherwise """ - print("DropboxService: Trying to move/rename file with identifier {} to identifier {}".format(identifier_from, identifier_to)) + print("DropboxService: Trying to move/rename file with identifier {} to identifier {}".format(identifier_from, + identifier_to)) dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN) url_from = settings.DROPBOX_IMAGE_FOLDER + identifier_from + '.jpg' @@ -102,7 +77,6 @@ class DropboxService(StorageServiceInterface): return True - @staticmethod def delete_file(filename: str) -> bool: """Delete an file from the dropbox storage. diff --git a/middleware/app_be/services/minioservice.py b/middleware/app_be/services/minioservice.py index 02e4046..166b3de 100644 --- a/middleware/app_be/services/minioservice.py +++ b/middleware/app_be/services/minioservice.py @@ -44,35 +44,6 @@ class MinioService(StorageServiceInterface): return False return True - @staticmethod - def update_file(filename: str, file: bytes) -> bool: - """Update a file on the minio storage. - - Finds the latest version of the current file and adds another - version to the storage. - :param filename: The filename without the version. - :param file: Byte representation of the file to save as new version - :return True if successful, False otherwise - """ - identifier = filename.strip('.jpg') - print("MinioService: Trying to update image with identifier ", identifier) - try: - headers = {'Content-Type': 'binary/octet-stream'} - i = 0 - while MinioService.read_file(identifier + '_' + str(i) + '.jpg') is not None: - print("MinioService: Version {} exists".format(identifier + '_' + str(i) + '.jpg')) - i = i + 1 - print("MinioService: Creating new version {}".format(identifier + '_' + str(i) + '.jpg')) - url = settings.AWS_HOST + identifier + '_' + str(i) + '.jpg' - r = requests.put(url, data=file, headers=headers) - if r.status_code == 200: - print("Successfully uploaded a new version with filename {}!".format(identifier + '_' + str(i) + '.jpg')) - else: - print("Something went wrong while updating") - except: - return False - return True - @staticmethod def move_file(identifier_from: str, identifier_to: str) -> bool: """Move/Rename a file on the S3 storage.