fix: storage and directories bug
This commit is contained in:
@@ -23,6 +23,7 @@ from .factory import (
|
||||
PURPOSE_BUCKETS,
|
||||
RCLONE_REMOTE_NAME,
|
||||
actual_bucket_name,
|
||||
build_storage_uri,
|
||||
build_storage_config,
|
||||
create_storage,
|
||||
rclone_remote_spec,
|
||||
@@ -34,6 +35,7 @@ __all__ = [
|
||||
"create_storage",
|
||||
"build_storage_config",
|
||||
"actual_bucket_name",
|
||||
"build_storage_uri",
|
||||
"workspaces_root",
|
||||
"rclone_remote_spec",
|
||||
"RCLONE_REMOTE_NAME",
|
||||
|
||||
@@ -78,6 +78,24 @@ def actual_bucket_name(purpose: str) -> str:
|
||||
return getattr(settings, f"s3_{purpose}_bucket")
|
||||
|
||||
|
||||
def build_storage_uri(bucket_name: str, object_key: str) -> str:
|
||||
"""根据 ``settings.storage_backend`` 构造对象的 storage_uri。
|
||||
|
||||
- s3 模式:``s3://{bucket_name}/{object_key}``
|
||||
- local 模式:``file://{absolute_bucket_path}/{object_key}``
|
||||
|
||||
local 模式下 ``bucket_name`` 是文件系统路径(见 ``actual_bucket_name``),
|
||||
不能直接用 ``s3://`` 前缀,否则会产生 ``s3:///data/version/...`` 这种
|
||||
非法 URI。因此返回 ``file://`` URI,并把相对路径先转成绝对路径。
|
||||
"""
|
||||
from common.config import settings # 延迟 import 避免循环
|
||||
|
||||
if settings.storage_backend == "local":
|
||||
absolute_path = Path(bucket_name).absolute().as_posix()
|
||||
return f"file://{absolute_path}/{object_key}"
|
||||
return f"s3://{bucket_name}/{object_key}"
|
||||
|
||||
|
||||
def build_storage_config(bucket_name: str) -> Dict[str, Any]:
|
||||
"""根据 ``settings.storage_backend`` 构造 ``create_storage()`` 的入参。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user