added return and failsafe

This commit is contained in:
Manuel Hude 2020-12-09 17:12:46 +01:00
parent 47dfe26ace
commit d093dbb5b9
2 changed files with 12 additions and 6 deletions

View File

@ -63,6 +63,9 @@ class MongoDBService:
except:
print("Could not insert Metadata")
return False
return True
@staticmethod
def deleteSingle(identifier):

View File

@ -60,7 +60,7 @@ class ImageEndpoint:
logger.debug('Actual Dropbox SHA512: {}'.format(actual_dropbox_hash))
if stored_hash != actual_dropbox_hash:
return JsonResponse('Stored hash does not match generated one! '
'stored: {} actual: {}'.format(stored_hash, actual_dropbox_hash), safe=False)
'stored: {} actual: {}'.format(stored_hash, actual_dropbox_hash), status=400, safe=False)
# get image bytes from MinIO
minio_image_bytes = MinioService.read_file(metadata['filename'])
@ -73,7 +73,7 @@ class ImageEndpoint:
logger.debug('Actual MinIO SHA512: {}'.format(actual_minio_hash))
if stored_hash != actual_minio_hash:
return JsonResponse('Stored hash does not match generated one! '
'stored: {} actual: {}'.format(stored_hash, actual_minio_hash), status=404, safe=False)
'stored: {} actual: {}'.format(stored_hash, actual_minio_hash), status=400, safe=False)
payload = {
'id': identifier,
@ -95,14 +95,17 @@ class ImageEndpoint:
decoded_image = WrapperService.unwrap_file(b64encoded_image)
MongoDBService.createSingle(metadata, identifier, decoded_image)
if not MongoDBService.createSingle(metadata, identifier, decoded_image):
print("Could not save metadata")
return JsonResponse({'Result': 'Error - could not upload to MongoDB', 'id': identifier, 'filename': filename}, status=500,safe=False)
if not DropboxService.create_file(filename, decoded_image):
print("Could not save image to dropbox")
return JsonResponse({'Result': 'Error - could not upload to Dropbox', 'id': identifier, 'filename': filename},status=500, safe=False)
if not MinioService.create_file(filename, decoded_image):
print("Could not save image to minio")
return JsonResponse({'id': identifier, 'filename': filename},
safe=False) # 'metadata': metadata response beinhaltet ObjectId welche nicht serializable is?
return JsonResponse({'Result': 'Error - could not upload to MinIO', 'id': identifier, 'filename': filename}, status=500, safe=False)
return JsonResponse({'id': identifier, 'filename': filename},safe=False)
@staticmethod
@api_view(['DELETE'])