Skip to content

Commit 38476cf

Browse files
(gfeat:storage) get storage instance based on settings
1 parent e9a6044 commit 38476cf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

application/storage/storage_creator.py

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from application.storage.base import BaseStorage
55
from application.storage.local import LocalStorage
66
from application.storage.s3 import S3Storage
7+
from application.core.settings import settings
78

89

910
class StorageCreator:
@@ -12,6 +13,16 @@ class StorageCreator:
1213
"s3": S3Storage,
1314
}
1415

16+
_instance = None
17+
18+
@classmethod
19+
def get_storage(cls) -> BaseStorage:
20+
if cls._instance is None:
21+
storage_type = getattr(settings, "STORAGE_TYPE", "local")
22+
cls._instance = cls.create_storage(storage_type)
23+
24+
return cls._instance
25+
1526
@classmethod
1627
def create_storage(cls, type_name: str, *args, **kwargs) -> BaseStorage:
1728
storage_class = cls.storages.get(type_name.lower())

0 commit comments

Comments
 (0)