Remove unneeded update function in storages
This commit is contained in:
parent
8c64333e27
commit
3f087c5d83
@ -55,32 +55,6 @@ class DropboxService(StorageServiceInterface):
|
|||||||
print("Error downloading file from dropbox")
|
print("Error downloading file from dropbox")
|
||||||
return file_bytes
|
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
|
@staticmethod
|
||||||
def move_file(identifier_from: str, identifier_to: str) -> bool:
|
def move_file(identifier_from: str, identifier_to: str) -> bool:
|
||||||
"""Move/Rename a file on the dropbox storage.
|
"""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
|
:param identifier_to: Location the file should be moved to
|
||||||
:return True on success, False otherwise
|
: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)
|
dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN)
|
||||||
url_from = settings.DROPBOX_IMAGE_FOLDER + identifier_from + '.jpg'
|
url_from = settings.DROPBOX_IMAGE_FOLDER + identifier_from + '.jpg'
|
||||||
@ -102,7 +77,6 @@ class DropboxService(StorageServiceInterface):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_file(filename: str) -> bool:
|
def delete_file(filename: str) -> bool:
|
||||||
"""Delete an file from the dropbox storage.
|
"""Delete an file from the dropbox storage.
|
||||||
|
|||||||
@ -44,35 +44,6 @@ class MinioService(StorageServiceInterface):
|
|||||||
return False
|
return False
|
||||||
return True
|
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
|
@staticmethod
|
||||||
def move_file(identifier_from: str, identifier_to: str) -> bool:
|
def move_file(identifier_from: str, identifier_to: str) -> bool:
|
||||||
"""Move/Rename a file on the S3 storage.
|
"""Move/Rename a file on the S3 storage.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user