Update storage.
This commit is contained in:
parent
6dca3a96e1
commit
3926b2d837
@ -188,28 +188,17 @@ class WebdavApplication(aiohttp.web.Application):
|
|||||||
statvfs = os.statvfs(path)
|
statvfs = os.statvfs(path)
|
||||||
return statvfs.f_bavail * statvfs.f_frsize
|
return statvfs.f_bavail * statvfs.f_frsize
|
||||||
|
|
||||||
async def handle_propfind(self, request):
|
|
||||||
if not await self.authenticate(request):
|
async def create_node(self, request, response_xml, full_path, depth):
|
||||||
return aiohttp.web.Response(
|
|
||||||
status=401, headers={"WWW-Authenticate": 'Basic realm="WebDAV"'}
|
|
||||||
)
|
|
||||||
requested_path = request.match_info.get("filename", "")
|
requested_path = request.match_info.get("filename", "")
|
||||||
abs_path = request['home'] / requested_path
|
abs_path = pathlib.Path(full_path)
|
||||||
if not abs_path.exists():
|
relative_path = str(full_path.relative_to(request['home']))
|
||||||
return aiohttp.web.Response(status=404, text="Directory not found")
|
|
||||||
nsmap = {"D": "DAV:"}
|
href_path = f"{relative_path}".strip("/")
|
||||||
response_xml = etree.Element("{DAV:}multistatus", nsmap=nsmap)
|
#href_path = href_path.replace("./","/")
|
||||||
directories = [requested_path]
|
|
||||||
if abs_path.is_dir():
|
|
||||||
directories.extend(os.listdir(abs_path))
|
|
||||||
for item in directories:
|
|
||||||
full_path = abs_path / item if item != requested_path else abs_path
|
|
||||||
href_path = f"/{requested_path}/{item}/" if item != requested_path else f"/{requested_path}/"
|
|
||||||
href_path = href_path.replace("//", "/")
|
href_path = href_path.replace("//", "/")
|
||||||
response = etree.SubElement(response_xml, "{DAV:}response")
|
response = etree.SubElement(response_xml, "{DAV:}response")
|
||||||
href = etree.SubElement(response, "{DAV:}href")
|
href = etree.SubElement(response, "{DAV:}href")
|
||||||
if not full_path.is_dir():
|
|
||||||
href_path = href_path.rstrip("/")
|
|
||||||
href.text = href_path
|
href.text = href_path
|
||||||
propstat = etree.SubElement(response, "{DAV:}propstat")
|
propstat = etree.SubElement(response, "{DAV:}propstat")
|
||||||
prop = etree.SubElement(propstat, "{DAV:}prop")
|
prop = etree.SubElement(propstat, "{DAV:}prop")
|
||||||
@ -248,6 +237,35 @@ class WebdavApplication(aiohttp.web.Application):
|
|||||||
lock_type_2 = etree.SubElement(lock_entry_2, "{DAV:}locktype")
|
lock_type_2 = etree.SubElement(lock_entry_2, "{DAV:}locktype")
|
||||||
etree.SubElement(lock_type_2, "{DAV:}write")
|
etree.SubElement(lock_type_2, "{DAV:}write")
|
||||||
etree.SubElement(propstat, "{DAV:}status").text = "HTTP/1.1 200 OK"
|
etree.SubElement(propstat, "{DAV:}status").text = "HTTP/1.1 200 OK"
|
||||||
|
|
||||||
|
if abs_path.is_dir() and depth != -1:
|
||||||
|
for item in abs_path.iterdir():
|
||||||
|
await self.create_node(request,response_xml, item, depth - 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def handle_propfind(self, request):
|
||||||
|
if not await self.authenticate(request):
|
||||||
|
return aiohttp.web.Response(
|
||||||
|
status=401, headers={"WWW-Authenticate": 'Basic realm="WebDAV"'}
|
||||||
|
)
|
||||||
|
|
||||||
|
depth = 0
|
||||||
|
try:
|
||||||
|
depth = int(request.headers.get("Depth", "0"))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
requested_path = request.match_info.get("filename", "")
|
||||||
|
abs_path = request['home'] / requested_path
|
||||||
|
if not abs_path.exists():
|
||||||
|
return aiohttp.web.Response(status=404, text="Directory not found")
|
||||||
|
nsmap = {"D": "DAV:"}
|
||||||
|
response_xml = etree.Element("{DAV:}multistatus", nsmap=nsmap)
|
||||||
|
directories = [requested_path]
|
||||||
|
|
||||||
|
await self.create_node(request, response_xml, abs_path, depth)
|
||||||
|
|
||||||
xml_output = etree.tostring(
|
xml_output = etree.tostring(
|
||||||
response_xml, encoding="utf-8", xml_declaration=True
|
response_xml, encoding="utf-8", xml_declaration=True
|
||||||
).decode()
|
).decode()
|
||||||
|
Loading…
Reference in New Issue
Block a user