Remove unneeded update function in storages

This commit is contained in:
Tobias Eidelpes 2021-01-08 19:11:18 +01:00
parent 8c64333e27
commit 3f087c5d83
2 changed files with 2 additions and 57 deletions

View File

@ -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.

View File

@ -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.