校验媒体文件是否存在缓存中
This commit is contained in:
parent
2d9e351f4c
commit
7df85d3483
|
|
@ -57,11 +57,22 @@ class MediaSource(BaseModel):
|
||||||
paths = media_url[5:].split('/')
|
paths = media_url[5:].split('/')
|
||||||
if len(paths) < 3:
|
if len(paths) < 3:
|
||||||
raise ValidationError("URN-s3 格式错误")
|
raise ValidationError("URN-s3 格式错误")
|
||||||
return MediaSource(path='/'.join(paths[2:]),
|
|
||||||
|
media_source = MediaSource(path='/'.join(paths[2:]),
|
||||||
protocol=MediaProtocol.s3,
|
protocol=MediaProtocol.s3,
|
||||||
endpoint=paths[0],
|
endpoint=paths[0],
|
||||||
bucket=paths[1],
|
bucket=paths[1],
|
||||||
urn=media_url)
|
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}
|
elif media_url.startswith('vod://'): # vod://{endpoint}/{subAppId}/{fileId}
|
||||||
paths = media_url[6:].split('/')
|
paths = media_url[6:].split('/')
|
||||||
if len(paths) < 3:
|
if len(paths) < 3:
|
||||||
|
|
@ -123,6 +134,7 @@ class MediaSource(BaseModel):
|
||||||
case _:
|
case _:
|
||||||
return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}"
|
return f"{self.protocol.value}/{self.endpoint}/{self.bucket}/{self.path}"
|
||||||
|
|
||||||
|
|
||||||
@computed_field(description="文件后缀名")
|
@computed_field(description="文件后缀名")
|
||||||
@cached_property
|
@cached_property
|
||||||
def file_extension(self) -> Optional[str]:
|
def file_extension(self) -> Optional[str]:
|
||||||
|
|
@ -187,3 +199,5 @@ class CacheResult(BaseModel):
|
||||||
|
|
||||||
class DownloadResult(BaseModel):
|
class DownloadResult(BaseModel):
|
||||||
urls: List[str] = Field(description="下载链接")
|
urls: List[str] = Field(description="下载链接")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue