Skip to content

Commit 51baed1

Browse files
committed
feat: config.Provider has new ignore_property_extra poperty, default is True
1 parent 94a80d4 commit 51baed1

9 files changed

Lines changed: 43 additions & 20 deletions

File tree

asgi_webdav/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Provider(BaseModel):
5353
uri: str
5454
home_dir: bool = False
5555
read_only: bool = False
56+
ignore_property_extra: bool = True
5657

5758

5859
class GuessTypeExtension(BaseModel):

asgi_webdav/dev/dev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
{
5252
"prefix": "/tmp",
5353
"uri": "file:///tmp",
54+
"ignore_property_extra": False,
5455
},
5556
{
5657
"prefix": "/memory",
5758
"uri": "memory:///",
59+
"ignore_property_extra": False,
5860
},
5961
{
6062
"prefix": "/~",

asgi_webdav/dev/litmus.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515
"prefix": "/",
1616
"uri": "memory:///",
1717
"read_only": True,
18+
"ignore_property_extra": False,
1819
},
1920
{
2021
"prefix": "/provider",
2122
"uri": "memory:///",
2223
"read_only": True,
24+
"ignore_property_extra": False,
2325
},
2426
{
2527
"prefix": "/provider/fs",
2628
"uri": "file:///tmp",
29+
"ignore_property_extra": False,
2730
},
2831
{
2932
"prefix": "/provider/memory",
3033
"uri": "memory:///",
34+
"ignore_property_extra": False,
3135
},
3236
],
3337
}

asgi_webdav/provider/dev_provider.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def __init__(
2525
config: Config,
2626
prefix: DAVPath,
2727
uri: str,
28-
home_dir: bool = False,
29-
read_only: bool = False,
28+
home_dir: bool,
29+
read_only: bool,
30+
ignore_property_extra: bool,
3031
):
3132
self.config = config
3233

@@ -46,6 +47,8 @@ def __init__(
4647
else:
4748
self.header_allow_methods = ",".join(DAV_METHODS).encode("utf-8")
4849

50+
self.ignore_property_extra = ignore_property_extra
51+
4952
self.dav_lock = DAVLock()
5053

5154
# https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Ranges

asgi_webdav/provider/file_system.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async def _create_dav_property_obj(
208208
)
209209

210210
# extra
211-
if request.propfind_only_fetch_basic:
211+
if self.ignore_property_extra or request.propfind_only_fetch_basic:
212212
return dav_property
213213

214214
properties_path = self._get_fs_properties_path(fs_path)
@@ -299,6 +299,9 @@ async def _do_propfind(self, request: DAVRequest) -> dict[DAVPath, DAVProperty]:
299299
return dav_properties
300300

301301
async def _do_proppatch(self, request: DAVRequest) -> int:
302+
if self.ignore_property_extra:
303+
return 207
304+
302305
fs_path = self._get_fs_path(request.dist_src_path, request.user.username)
303306
properties_path = self._get_fs_properties_path(fs_path)
304307
if not await aiofiles.ospath.exists(fs_path):

asgi_webdav/provider/memory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ async def _do_propfind(self, request: DAVRequest) -> dict[DAVPath, DAVProperty]:
278278
return dav_properties
279279

280280
async def _do_proppatch(self, request: DAVRequest) -> int:
281+
if self.ignore_property_extra:
282+
return 207
283+
281284
async with self.fs_lock:
282285
fs_member = self.fs_root.get_member(request.dist_src_path)
283286
if fs_member is None:

asgi_webdav/web_dav.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,22 @@ class PrefixProviderInfo:
7878
provider: DAVProvider
7979
home_dir: bool
8080
read_only: bool
81+
ignore_property_extra: bool
8182

8283
def __str__(self):
8384
flag_list = list()
8485
if self.home_dir:
85-
flag_list.append("Home")
86+
flag_list.append("home_dir")
8687
if self.read_only:
87-
flag_list.append("ReadOnly")
88+
flag_list.append("read_only")
89+
if self.ignore_property_extra:
90+
flag_list.append("ignore_property_extra")
8891

89-
if flag_list:
90-
flag_str = f"--[{'/'.join(flag_list)}]-->"
91-
else:
92-
flag_str = "-->"
92+
flag_str = ",".join(flag_list)
93+
if flag_str:
94+
flag_str = f" ,[{flag_str}]"
9395

94-
return f"{self.prefix} {flag_str} {self.provider}"
96+
return f"{self.prefix} ==> {self.provider}{flag_str}"
9597

9698

9799
class WebDAV:
@@ -115,13 +117,15 @@ def __init__(self, config: Config):
115117
uri=pm.uri,
116118
home_dir=pm.home_dir,
117119
read_only=pm.read_only,
120+
ignore_property_extra=pm.ignore_property_extra,
118121
)
119122
ppi = PrefixProviderInfo(
120123
prefix=DAVPath(pm.prefix),
121124
prefix_weight=len(pm.prefix),
122125
provider=provider,
123126
home_dir=pm.home_dir,
124127
read_only=pm.read_only,
128+
ignore_property_extra=pm.ignore_property_extra,
125129
)
126130
self.prefix_provider_mapping.append(ppi)
127131
logger.info(f"Mapping Prefix: {ppi}")

docs/changelog.en.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.5.0 - ?
44

5+
- Breaking Change
6+
- feat: `config.Provider` has new `ignore_property_extra` poperty, default is `True`
57
- Allow authenticating any user from LDAP server, thanks [PIC](https://www.pic.es)
68
- feat: better timezone support, get timezone from env `TZ`
79
- feat: `HTTPBasicAuth`'s cache is now configurable

docs/reference/config-file.en.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ When the file exists, the mapping relationship is defined by the file content.
6262
},
6363
{
6464
"prefix": "/provider/memory",
65-
"uri": "memory:///"
65+
"uri": "memory:///",
66+
"ignore_property_extra": false
6667
},
6768
{
6869
"prefix": "/~",
@@ -187,23 +188,23 @@ Example
187188
### `Provider` Object
188189

189190
- Introduced in 0.1
190-
- Last updated in 1.4.0
191+
- Last updated in 1.5.0
191192

192-
| Key | Value Type | Default Value |
193-
| --------- | ---------- | ------------- |
194-
| prefix | str | - |
195-
| uri | str | - |
196-
| home_dir | bool | `false` |
197-
| read_only | bool | `false` |
193+
| Key | Value Type | Default Value |
194+
| --------------------- | ---------- | ------------- |
195+
| prefix | str | - |
196+
| uri | str | - |
197+
| home_dir | bool | `false` |
198+
| read_only | bool | `false` |
199+
| ignore_property_extra | bool | `true` |
198200

199201
### Home Directory
200202

201203
- When `home_dir` is `true`, it is the home directory. The `prefix` recommends using `/~` or `/home`.
202-
203204
- When `home_dir` is `true` and `prefix` is `/~` and `uri` is `file:///data/homes` and `username` is `user_x`
204205
; `http://webdav.host/~/path` will map to `file:///data/homes/user_x/path`.
205-
206206
- When `read_only` is `true`; it is a read only directory, include subdirectories.
207+
- When `ignore_property_extra` is `true`; The Provider ignores the extra property, based on the Provider's implementation.
207208

208209
## for Rules Process
209210

0 commit comments

Comments
 (0)