Added delete all in dropbox service and iot client help command

This commit is contained in:
Martin Schett 2020-12-06 18:24:07 +01:00
parent ce34ce8562
commit ddf0cbf2d7
3 changed files with 34 additions and 2 deletions

View File

@ -171,6 +171,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
print("fetch - gets the next image from database if exists")
print("fetchall - get all images")
print("delete - delets the next image from db if exists")
print("delete - delets all images from the service")
print("rapid <#amount> - next <amound> images in line are sent to backend in 2 second intervals")
print("skip [<#amount>] - skips the next <amount> number of images in line or 1 if no <amount> is given")
print("set <#index> - sets image on given <index> as next in line")

View File

@ -62,3 +62,18 @@ class DropboxService:
except:
return False
return True
@staticmethod
def delete_all() -> bool:
"""Delete every file from the dropbox storage.
:return: Whether the storage was successfully emptied
"""
try:
dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN)
dbx.files_delete_v2(settings.DROPBOX_IMAGE_FOLDER[:-1])
dbx.files_create_folder_v2(settings.DROPBOX_IMAGE_FOLDER[:-1])
except dropbox.exceptions.ApiError as e:
print(e)
return False
return True

View File

@ -109,19 +109,35 @@ class ImageEndpoint:
def image_api_delete(request: HttpRequest, identifier):
logger.debug('Image DELETE single call: {}'.format(request))
result_bool = True
# get metadata from MongoDB
metadata = MongoDBService.getSingle(identifier)
if not metadata:
return JsonResponse({'Result': 'Error - could not find any metadata in mongoDB.',
'id': identifier}, status=404, safe=False)
resp = MongoDBService.deleteSingle(identifier)
print(resp)
return JsonResponse({'Result': 'success1'}, safe=False)
if not DropboxService.delete_file(metadata['filename']):
print('Error deleting file in dropbox')
result_bool = False
return JsonResponse({'Result': result_bool}, safe=False)
@staticmethod
@api_view(['DELETE'])
def image_api_delete_all(request: HttpRequest):
logger.debug('Image DELETE single call: {}'.format(request))
result_bool = True
resp = MongoDBService.deleteAll()
print(resp)
return JsonResponse({'Result': 'success1'}, safe=False)
if not DropboxService.delete_all():
print('Error deleting dropbox folder')
result_bool = False
return JsonResponse({'Result': result_bool}, safe=False)