2022-03-16 18:50:29 +00:00
|
|
|
from loguru import logger
|
2022-02-22 15:03:35 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
|
|
|
|
|
|
class Storage(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
def __init__(self, config): pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2022-03-15 10:32:39 +00:00
|
|
|
def get_cdn_url(self, key): pass
|
2022-02-22 15:03:35 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
2022-03-15 10:32:39 +00:00
|
|
|
def exists(self, key): pass
|
2022-02-22 15:03:35 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def uploadf(self, file, key, **kwargs): pass
|
|
|
|
|
|
|
|
def upload(self, filename: str, key: str, **kwargs):
|
2022-03-16 18:50:29 +00:00
|
|
|
logger.debug(f'[{self.__class__.__name__}] uploading file {filename} with key {key}')
|
2022-05-25 10:23:52 +00:00
|
|
|
with open(filename, 'rb') as f:
|
|
|
|
self.uploadf(f, key, **kwargs)
|