fix cache path

This commit is contained in:
jxxghp
2024-08-29 15:39:12 +08:00
parent f4dfaa0519
commit 264cd2658b
3 changed files with 7 additions and 3 deletions

View File

@@ -31,7 +31,7 @@ def douban_img(imgurl: str) -> Any:
# 获取Url中除域名外的路径
url_path = "/".join(imgurl.split('/')[3:])
# 生成缓存文件路径
cache_path = settings.TEMP_PATH / url_path
cache_path = settings.CACHE_PATH / 'images' / url_path
# 如果缓存文件不存在,下载图片并保存
if not cache_path.exists():
response = __download_image(imgurl)

View File

@@ -53,7 +53,7 @@ def cache_img(url: str) -> Any:
# 获取Url中除域名外的路径
url_path = "/".join(url.split('/')[3:])
# 生成缓存文件路径
cache_path = settings.TEMP_PATH / url_path
cache_path = settings.CACHE_PATH / 'images' / url_path
# 豆瓣设置Referer
referer = None
if 'doubanio.com' in url:

View File

@@ -158,7 +158,7 @@ class Settings(BaseSettings):
REPO_GITHUB_TOKEN: Optional[str] = None
# 大内存模式
BIG_MEMORY_MODE: bool = False
# 全局图片缓存
# 全局图片缓存,将媒体图片缓存到本地
GLOBAL_IMAGE_CACHE: bool = False
@validator("SUBSCRIBE_RSS_INTERVAL",
@@ -191,6 +191,10 @@ class Settings(BaseSettings):
def TEMP_PATH(self):
return self.CONFIG_PATH / "temp"
@property
def CACHE_PATH(self):
return self.CONFIG_PATH / "cache"
@property
def ROOT_PATH(self):
return Path(__file__).parents[2]