Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAPI, find method doesn't work well for Group Folders #263

Open
zhongzishi opened this issue Jun 1, 2024 · 3 comments
Open

FileAPI, find method doesn't work well for Group Folders #263

zhongzishi opened this issue Jun 1, 2024 · 3 comments
Labels
nc upstream issue waiting for it to be fixed/implemented in the Nextcloud

Comments

@zhongzishi
Copy link

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

  1. nc.files.find(["like","name","%.png"],path="GroupFolderB/")

image

  1. nc.files.find(["like","name","%.png"],path="GroupFolderB/subFolderA")

image
image

Expected Results

Returns matching files under the target path (including subfolders)

Actual Results

Returns empty results.

Setup configuration

nc_py_api commit version: fd92a25

NextCloud 28.0.4

@bigcat88
Copy link
Contributor

bigcat88 commented Jun 2, 2024

Do you know if this is perhaps by design or are you sure PROPFIND is supposed to work with subfolders in Groupdolders?

@zhongzishi
Copy link
Author

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

@bigcat88
Copy link
Contributor

response = requests.request("PROPFIND", url, headers=headers, data=data, auth=auth)

Unfortunately, it is a PROPFIND request, and not SEARCH

I found such issue:

nextcloud/groupfolders#2583

Looking at code, I do not see a handler for SEARCH requests:

https://github.com/nextcloud/groupfolders/blob/master/lib/DAV/PropFindPlugin.php

@bigcat88 bigcat88 added the nc upstream issue waiting for it to be fixed/implemented in the Nextcloud label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nc upstream issue waiting for it to be fixed/implemented in the Nextcloud
Projects
None yet
Development

No branches or pull requests

2 participants