mirror of
https://github.com/corca-ai/EVAL
synced 2024-11-01 03:20:10 +00:00
26 lines
711 B
Python
26 lines
711 B
Python
|
import os
|
||
|
import shutil
|
||
|
|
||
|
from env import DotEnv
|
||
|
from .base import AbstractUploader
|
||
|
|
||
|
|
||
|
class StaticUploader(AbstractUploader):
|
||
|
STATIC_DIR = "static"
|
||
|
|
||
|
def __init__(self, server: str):
|
||
|
self.server = server
|
||
|
|
||
|
@staticmethod
|
||
|
def from_settings(settings: DotEnv) -> "StaticUploader":
|
||
|
return StaticUploader(settings["SERVER"])
|
||
|
|
||
|
def get_url(self, uploaded_path: str) -> str:
|
||
|
return f"{self.server}/{uploaded_path}"
|
||
|
|
||
|
def upload(self, filepath: str):
|
||
|
upload_path = os.path.join(StaticUploader.STATIC_DIR, filepath)
|
||
|
os.makedirs(os.path.dirname(upload_path), exist_ok=True)
|
||
|
shutil.copy(filepath, upload_path)
|
||
|
return f"{self.server}/{upload_path}"
|