clear settings and os.envieon

Former-commit-id: f02ff51326cdaaad4e0e923f9b8782d0a3d24327
pull/160/head
Kye 2 years ago
parent 78dc1ab8db
commit 56f4371910

@ -367,19 +367,17 @@ class FileHandler:
def handle(self, url: str) -> str: def handle(self, url: str) -> str:
try: try:
if url.startswith(settings["SERVER"]): if url.startswith(os.environ.get("SERVER", "")):
local_filepath = url[len(settings["SERVER"]) + 1 :] local_filepath = url[len(os.environ.get("SERVER", "")) + 1 :]
local_filename = Path("file") / local_filepath.split("/")[-1] local_filename = Path("file") / local_filepath.split("/")[-1]
src = self.path / local_filepath src = self.path / local_filepath
dst = self.path / settings["PLAYGROUND_DIR"] / local_filename dst = self.path / os.environ.get("PLAYGROUND_DIR", "./playground") / local_filename
os.makedirs(os.path.dirname(dst), exist_ok=True) os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy(src, dst) shutil.copy(src, dst)
else: else:
local_filename = self.download(url) local_filename = self.download(url)
handler = self.handlers.get(FileType.from_url(url))
try: if handler is None:
handler = self.handlers[FileType.from_url(url)]
except KeyError:
if FileType.from_url(url) == FileType.IMAGE: if FileType.from_url(url) == FileType.IMAGE:
raise Exception( raise Exception(
f"No handler for {FileType.from_url(url)}. " f"No handler for {FileType.from_url(url)}. "
@ -387,10 +385,9 @@ class FileHandler:
) )
else: else:
raise Exception(f"No handler for {FileType.from_url(url)}") raise Exception(f"No handler for {FileType.from_url(url)}")
handler.handle(local_filename) return handler.handle(local_filename)
except Exception as e: except Exception as e:
raise e raise e
########################### => base end ########################### => base end

Loading…
Cancel
Save