Open zhongzishi opened 4 months ago
Do you know if this is perhaps by design or are you sure PROPFIND is supposed to work with subfolders in Groupdolders?
PROPFIND works with subfolders in Groupfolder, here is an example with NC webDAV api:
import requests
from requests.auth import HTTPBasicAuth
import xml.etree.ElementTree as ET
def get_files_in_folder(url, auth, headers):
data = '''<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:resourcetype/>
<d:displayname/>
<d:getcontentlength/>
<d:getlastmodified/>
</d:prop>
</d:propfind>'''
response = requests.request("PROPFIND", url, headers=headers, data=data, auth=auth)
response.raise_for_status()
return response.text
def parse_response(response_text):
root = ET.fromstring(response_text)
items = []
for response in root.findall('{DAV:}response'):
href = response.find('{DAV:}href').text
displayname = response.find('.//{DAV:}displayname').text
resourcetype = response.find('.//{DAV:}resourcetype/{DAV:}collection')
contentlength = response.find('.//{DAV:}getcontentlength')
lastmodified = response.find('.//{DAV:}getlastmodified').text if response.find('.//{DAV:}getlastmodified') is not None else None
items.append({
'href': href,
'displayname': displayname,
'is_dir': resourcetype is not None,
'contentlength': contentlength.text if contentlength is not None else None,
'lastmodified': lastmodified
})
return items
folder_url = "https://example.nextcould.com/remote.php/dav/files/userA/GroupFolderB/subFolderA"
auth = HTTPBasicAuth(NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD)
headers = {
"Depth": "1",
"Content-Type": "application/xml",
"Accept": "application/json"
}
response_text = get_files_in_folder(folder_url, auth, headers)
files = parse_response(response_text)
for file in files:
print(f"Name: {file['displayname']}, Size: {file['contentlength']}, Last Modified: {file['lastmodified']}, Path: {file['href']}")
And I'm able to get files/subfolders under this group folder.
Name: subFolderA, Size: None, Last Modified: Sat, 01 Jun 2024 01:54:12 GMT, Path: /remote.php/dav/files/userA/GroupFolderB/subFolderA/
Name: Bworkflow_api (1).json, Size: 4767, Last Modified: Mon, 20 May 2024 16:50:28 GMT, Path: /remote.php/dav/files/userA/GroupFolderB/subFolderA/Bworkflow_api%20(1).json
Name: download.png, Size: 29409, Last Modified: Wed, 01 May 2024 14:10:38 GMT, Path: /remote.php/dav/files/userA/GroupFolderB/subFolderA/download.png
response = requests.request("PROPFIND", url, headers=headers, data=data, auth=auth)
Unfortunately, it is a PROPFIND
request, and not SEARCH
I found such issue:
https://github.com/nextcloud/groupfolders/issues/2583
Looking at code, I do not see a handler for SEARCH
requests:
https://github.com/nextcloud/groupfolders/blob/master/lib/DAV/PropFindPlugin.php
Describe the bug
When the search target is a Group Folder, if the path contains only the root folder, the Find method works great. I can get all matching files, even in deep subfolders. But if the path contains a subfolder, the search result is empty.
When the search target is other than a Group Folder (personal folder or shared folder), it works great with paths containing subfolders.
Steps/Code to Reproduce
nc.files.find(["like","name","%.png"],path="GroupFolderB/")
nc.files.find(["like","name","%.png"],path="GroupFolderB/subFolderA")
Expected Results
Returns matching files under the target path (including subfolders)
Actual Results
Returns empty results.
Setup configuration
nc_py_api commit version: fd92a25d8bf02d02f462d26f142553778d3a3255
NextCloud 28.0.4