From 7df85d348342813262370e22c8428681e1f295e9 Mon Sep 17 00:00:00 2001 From: gexianmeng Date: Tue, 20 May 2025 10:59:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=AA=92=E4=BD=93=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BowongModalFunctions/models/media_model.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/BowongModalFunctions/models/media_model.py b/src/BowongModalFunctions/models/media_model.py index 7122f47..335bf02 100644 --- a/src/BowongModalFunctions/models/media_model.py +++ b/src/BowongModalFunctions/models/media_model.py @@ -57,11 +57,22 @@ class MediaSource(BaseModel): paths = media_url[5:].split('/') if len(paths) < 3: raise ValidationError("URN-s3 格式错误") - return MediaSource(path='/'.join(paths[2:]), + + media_source = MediaSource(path='/'.join(paths[2:]), protocol=MediaProtocol.s3, endpoint=paths[0], bucket=paths[1], urn=media_url) + + s3_mount_path = config.S3_mount_dir + cache_path = os.path.join(s3_mount_path, media_source.cache_filepath) + + # 校验媒体文件是否存在缓存中 + if not os.path.exists(cache_path): + raise ValueError(f"媒体文件 {media_source.cache_filepath} 不存在于缓存中") + + return media_source + elif media_url.startswith('vod://'): # vod://{endpoint}/{subAppId}/{fileId} paths = media_url[6:].split('/') if len(paths) < 3: @@ -123,6 +134,7 @@ class MediaSource(BaseModel): case _: return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}" + @computed_field(description="文件后缀名") @cached_property def file_extension(self) -> Optional[str]: @@ -187,3 +199,5 @@ class CacheResult(BaseModel): class DownloadResult(BaseModel): urls: List[str] = Field(description="下载链接") + +