From da633a6e57e1898166b74072872d7e007c587e8e Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 5 Apr 2024 21:40:27 +0800 Subject: [PATCH] Fix the bug that mistakenly created a directory instead of a file --- app/services/material.py | 3 +++ app/utils/utils.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/material.py b/app/services/material.py index fd48b24..bc5efaa 100644 --- a/app/services/material.py +++ b/app/services/material.py @@ -84,6 +84,9 @@ def save_video(video_url: str, save_dir: str = "") -> str: if not save_dir: save_dir = utils.storage_dir("cache_videos") + if not os.path.exists(save_dir): + os.makedirs(save_dir) + url_without_query = video_url.split("?")[0] url_hash = utils.md5(url_without_query) video_id = f"vid-{url_hash}" diff --git a/app/utils/utils.py b/app/utils/utils.py index 086e65c..d784282 100644 --- a/app/utils/utils.py +++ b/app/utils/utils.py @@ -70,8 +70,6 @@ def storage_dir(sub_dir: str = ""): d = os.path.join(root_dir(), "storage") if sub_dir: d = os.path.join(d, sub_dir) - if not os.path.exists(d): - os.makedirs(d) return d