60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""
|
||
WebDAV 文件管理路由
|
||
使用 WsgiDAV 开源库提供完整的 WebDAV 协议支持
|
||
为 projects/{resource_type}/ 目录提供 WebDAV 协议支持
|
||
支持的资源类型: robot, docs
|
||
"""
|
||
|
||
from pathlib import Path
|
||
|
||
from wsgidav.wsgidav_app import WsgiDAVApp
|
||
from wsgidav.fs_dav_provider import FilesystemProvider
|
||
|
||
from utils.settings import WEBDAV_USERNAME, WEBDAV_PASSWORD
|
||
|
||
PROJECTS_BASE_DIR = Path("projects")
|
||
ALLOWED_RESOURCE_TYPES = {"robot", "docs"}
|
||
|
||
# 确保基础目录存在
|
||
for resource_type in ALLOWED_RESOURCE_TYPES:
|
||
(PROJECTS_BASE_DIR / resource_type).mkdir(parents=True, exist_ok=True)
|
||
|
||
# 构建 provider_mapping:每个资源类型映射到对应目录
|
||
provider_mapping = {}
|
||
for resource_type in ALLOWED_RESOURCE_TYPES:
|
||
abs_path = str((PROJECTS_BASE_DIR / resource_type).resolve())
|
||
provider_mapping[f"/{resource_type}"] = FilesystemProvider(abs_path)
|
||
|
||
config = {
|
||
"mount_path": "/webdav",
|
||
"provider_mapping": provider_mapping,
|
||
"http_authenticator": {
|
||
"domain_controller": "wsgidav.dc.simple_dc.SimpleDomainController",
|
||
"accept_basic": True,
|
||
"accept_digest": False,
|
||
"default_to_digest": False,
|
||
},
|
||
"simple_dc": {
|
||
"user_mapping": {
|
||
"*": {
|
||
WEBDAV_USERNAME: {
|
||
"password": WEBDAV_PASSWORD,
|
||
},
|
||
},
|
||
},
|
||
},
|
||
"verbose": 1,
|
||
"lock_storage": True,
|
||
"property_manager": True,
|
||
"dir_browser": {
|
||
"enable": True,
|
||
"icon": True,
|
||
"response_trailer": "",
|
||
},
|
||
"hotfixes": {
|
||
"re_encode_path_info": True,
|
||
},
|
||
}
|
||
|
||
wsgidav_app = WsgiDAVApp(config)
|