Rewrote storage services to implement new interface

This commit is contained in:
Martin Schett
2020-12-28 17:29:14 +01:00
parent 6d9f1a856d
commit 96b94f5c89
4 changed files with 112 additions and 61 deletions
@@ -0,0 +1,53 @@
class StorageServiceInterface:
name = "StorageServiceInterface"
@staticmethod
def check() -> bool:
pass
@staticmethod
def create_file(filename: str, file: bytes) -> bool:
"""Create / save (or overwrite) an file on the storage.
:param filename: filename
:param file: bytes representation of the file
:return: Whether file was successfully uploaded
"""
pass
@staticmethod
def read_file(filename: str) -> bytes:
"""Read file on the storage.
:param filename: filename
:return: bytes representation of the file or None on error
"""
pass
@staticmethod
def update_file(filename: str, file: bytes) -> bool:
"""Update (currently: overwrite) an file on the storage.
:param filename: filename of the file
:param file: bytes representation of the file
:return: Whether file was successfully uploaded
"""
pass
@staticmethod
def delete_file(filename: str) -> bool:
"""Delete an file from the storage.
:param filename: filename of the file
:return: Whether file was successfully deleted
"""
pass
@staticmethod
def delete_all() -> bool:
"""Delete every file from the storage.
:return: Whether the storage was successfully emptied
"""
pass
+6 -3
View File
@@ -2,8 +2,12 @@ import requests
from django.conf import settings
import dropbox
from app_be.services.StorageServiceInterface import StorageServiceInterface
class DropboxService:
class DropboxService(StorageServiceInterface):
name = "Dropbox"
@staticmethod
def check() -> bool:
@@ -17,7 +21,6 @@ class DropboxService:
return False
return True
@staticmethod
def create_file(filename: str, file: bytes) -> bool:
"""Create / save (or overwrite) an file on the dropbox storage.
@@ -89,4 +92,4 @@ class DropboxService:
except dropbox.exceptions.ApiError as e:
print(e)
return False
return True
return True
+6 -1
View File
@@ -6,7 +6,12 @@ import xml.etree.ElementTree as ET
import requests
from django.conf import settings
class MinioService:
from app_be.services.StorageServiceInterface import StorageServiceInterface
class MinioService(StorageServiceInterface):
name = "MinIO"
@staticmethod
def check() -> bool: