fix: 修复HTTP协议视频文件的CDN URL生成和S3存储路径问题
- 修复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
This commit is contained in:
parent
843e113fb5
commit
904f93a74d
|
|
@ -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挂载地址")
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue