base_storage.py 607 B

123456789101112131415161718192021222324
  1. from loguru import logger
  2. from abc import ABC, abstractmethod
  3. from pathlib import Path
  4. class Storage(ABC):
  5. TMP_FOLDER = "tmp/"
  6. @abstractmethod
  7. def __init__(self, config): pass
  8. @abstractmethod
  9. def get_cdn_url(self, key): pass
  10. @abstractmethod
  11. def exists(self, key): pass
  12. @abstractmethod
  13. def uploadf(self, file, key, **kwargs): pass
  14. def upload(self, filename: str, key: str, **kwargs):
  15. logger.debug(f'[{self.__class__.__name__}] uploading file {filename} with key {key}')
  16. with open(filename, 'rb') as f:
  17. self.uploadf(f, key, **kwargs)