fix update of images;
This commit is contained in:
parent
8e24d0333e
commit
7207080b66
@ -70,7 +70,7 @@ class DropboxService(StorageServiceInterface):
|
|||||||
return file_bytes
|
return file_bytes
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def move_file(identifier_from: str, identifier_to: str, file: bytes) -> bool:
|
def move_file(identifier_from: str, identifier_to: str, file: bytes = None) -> bool:
|
||||||
"""Move/Rename a file on the dropbox storage.
|
"""Move/Rename a file on the dropbox storage.
|
||||||
|
|
||||||
:param identifier_from: Location of the file to be moved
|
:param identifier_from: Location of the file to be moved
|
||||||
|
|||||||
@ -74,20 +74,22 @@ class MongoDBService:
|
|||||||
|
|
||||||
old = {"identifier": identifier} # Query for old version
|
old = {"identifier": identifier} # Query for old version
|
||||||
|
|
||||||
metadata_orig = MongoDBService.getSingle(identifier)
|
existing_meta_data_copy = MongoDBService.getSingle(identifier)
|
||||||
metadata_new = metadata_orig
|
id_for_previous = identifier + '_' + str(meta['version'])
|
||||||
metadata_new['previous'] = identifier + '_' + str(metadata_orig['version'])
|
existing_meta_data_copy['previous'] = id_for_previous
|
||||||
identifier_changed = identifier + '_' + str(metadata_orig['version']) # Set identifier to include version
|
identifier_changed = id_for_previous # Set identifier to include version
|
||||||
metadata_new['version'] = str(int(metadata_new['version']) + 1) # Increment version by one
|
|
||||||
|
|
||||||
metadata_new.update(meta)
|
del meta['filename']
|
||||||
|
existing_meta_data_copy.update(meta)
|
||||||
|
|
||||||
|
existing_meta_data_copy['version'] = meta['version'] + 1 # Increment version by one
|
||||||
|
|
||||||
print("MongoDBService: identifier_changed: ", identifier_changed)
|
print("MongoDBService: identifier_changed: ", identifier_changed)
|
||||||
col.update_one(old, {"$set": {"identifier": identifier_changed, "filename": identifier_changed + '.jpg'}})
|
col.update_one(old, {"$set": {"identifier": identifier_changed, "filename": identifier_changed + '.jpg'}})
|
||||||
|
|
||||||
print("MongoDBService: Old object is ", col.find_one({"identifier": identifier_changed}))
|
print("MongoDBService: Old object is ", col.find_one({"identifier": identifier_changed}))
|
||||||
|
|
||||||
MongoDBService.createSingle(metadata_new, identifier, decoded_image)
|
MongoDBService.createSingle(existing_meta_data_copy, identifier, decoded_image)
|
||||||
print("MongoDBService: New object is ", col.find_one({"identifier": identifier}))
|
print("MongoDBService: New object is ", col.find_one({"identifier": identifier}))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@ -210,7 +210,6 @@ class ImageEndpoint:
|
|||||||
def image_api_update(request, identifier):
|
def image_api_update(request, identifier):
|
||||||
logger.debug('Image UPDATE single call: {}'.format(request))
|
logger.debug('Image UPDATE single call: {}'.format(request))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = json.loads(request.body)
|
payload = json.loads(request.body)
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
@ -222,7 +221,7 @@ class ImageEndpoint:
|
|||||||
'Error': str(e)}, status=500, safe=False)
|
'Error': str(e)}, status=500, safe=False)
|
||||||
|
|
||||||
b64encoded_image = payload['image_data']
|
b64encoded_image = payload['image_data']
|
||||||
identifier = payload['id']
|
# identifier = identifier
|
||||||
metadata = payload['metadata']
|
metadata = payload['metadata']
|
||||||
filename = payload['metadata']['filename']
|
filename = payload['metadata']['filename']
|
||||||
|
|
||||||
@ -233,14 +232,18 @@ class ImageEndpoint:
|
|||||||
'id': identifier}, status=404, safe=False)
|
'id': identifier}, status=404, safe=False)
|
||||||
|
|
||||||
metadata['version'] = mongodb_metadata['version']
|
metadata['version'] = mongodb_metadata['version']
|
||||||
|
filename = mongodb_metadata['filename']
|
||||||
|
|
||||||
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
decoded_image = WrapperService.unwrap_file(b64encoded_image)
|
||||||
|
|
||||||
MongoDBService.updateSingle(identifier, decoded_image, metadata)
|
MongoDBService.updateSingle(identifier, decoded_image, metadata)
|
||||||
|
|
||||||
|
# TODO TOBIAS get old image for MinIO
|
||||||
|
old_bytes = None
|
||||||
|
|
||||||
for service in ImageEndpoint.storageServiceList:
|
for service in ImageEndpoint.storageServiceList:
|
||||||
orig_new_name = identifier + '_' + str(metadata['version']) + '.jpg'
|
orig_new_name = identifier + '_' + str(metadata['version']) + '.jpg'
|
||||||
if not service.move_file(identifier, orig_new_name, decoded_image):
|
if not service.move_file(identifier, orig_new_name, old_bytes):
|
||||||
print("Could not move file from {} to {}".format(identifier, orig_new_name))
|
print("Could not move file from {} to {}".format(identifier, orig_new_name))
|
||||||
if not service.create_file(filename, decoded_image):
|
if not service.create_file(filename, decoded_image):
|
||||||
print("Could not save updated image to " + service.name)
|
print("Could not save updated image to " + service.name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user