From 904f93a74d1d14c0415d72f2f3ec7263e4e147a0 Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 23 Sep 2025 10:40:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DHTTP=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=96=87=E4=BB=B6=E7=9A=84CDN=20URL=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=92=8CS3=E5=AD=98=E5=82=A8=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复cache_filepath中的双斜杠问题,移除路径开头的斜杠 - 修复get_cdn_url()方法,对HTTP协议使用cache_filepath确保路径一致性 - 修复cache_submit.py中重复的协议前缀问题 - 确保CDN URL与S3存储路径完全匹配,解决AccessDenied错误 现在的映射关系: - 存储: s3://ap-northeast-2/modal-media-cache/http/videos.pexels.com/video-files/xxx.mp4 - CDN: https://cdn.roasmax.cn/http/videos.pexels.com/video-files/xxx.mp4 --- src/BowongModalFunctions/models/cache_tasks/models.py | 5 ++++- src/cluster/video_apps/cache_submit.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BowongModalFunctions/models/cache_tasks/models.py b/src/BowongModalFunctions/models/cache_tasks/models.py index 886fb9e..432516d 100644 --- a/src/BowongModalFunctions/models/cache_tasks/models.py +++ b/src/BowongModalFunctions/models/cache_tasks/models.py @@ -126,6 +126,8 @@ class MediaSource(BaseModel): return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}" case MediaProtocol.http: clean_path = self.path.split('?')[0] if '?' in self.path else self.path + # 移除路径开头的斜杠,避免双斜杠问题 + clean_path = clean_path.lstrip('/') return f"{self.protocol.value}/{self.endpoint}/{clean_path}" case _: return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}" @@ -163,7 +165,8 @@ class MediaSource(BaseModel): if self.protocol == MediaProtocol.s3: return f"{self.path}" elif self.protocol == MediaProtocol.http: - return f"{self.protocol.value}/{self.path}" + # 对于HTTP协议,使用cache_filepath确保路径一致性 + return self.cache_filepath return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}" @computed_field(description="CDN挂载地址") diff --git a/src/cluster/video_apps/cache_submit.py b/src/cluster/video_apps/cache_submit.py index fa1594c..5843cb9 100644 --- a/src/cluster/video_apps/cache_submit.py +++ b/src/cluster/video_apps/cache_submit.py @@ -190,7 +190,7 @@ with downloader_image.imports(): raise e case MediaProtocol.http: try: - cache_filepath = f"{config.S3_mount_dir}/{media.protocol.value}/{media.cache_filepath}" + cache_filepath = f"{config.S3_mount_dir}/{media.cache_filepath}" os.makedirs(os.path.dirname(cache_filepath), exist_ok=True) download_large_file(url=media.__str__(), output_path=cache_filepath) except Exception as e: