feat: enhance display name handling for WebDAV entries and directory collections

This commit is contained in:
Jaime Idolpx 2026-06-07 17:59:06 -04:00
parent 4a2f6032d2
commit ed302d7156
2 changed files with 12 additions and 1 deletions

View File

@ -126,8 +126,12 @@ function pathFromUri(uri: string, baseUrl: string): string {
function toEntryInfo(e: WebDAVEntry, baseUrl: string): EntryInfo {
const rawPath = e.path && e.path.length > 0 ? e.path : e.uri;
const fullPath = pathFromUri(rawPath, baseUrl);
// Some servers (notably webdav3.py) report the full path as the
// <displayname> for collections. Always use the leaf of the resolved
// path so the UI shows a name, not a path.
const name = basename(fullPath) || e.name;
return {
name: e.name,
name,
path: fullPath,
type: e.isDir ? 'folder' : 'file',
size: typeof e.size === 'number' ? e.size : 0,

View File

@ -161,6 +161,13 @@ class DirCollection(FileMember, Collection):
p = FileMember.getProperties(self) # inherit file properties
p['iscollection'] = 1
p['getcontenttype'] = DirCollection.COLLECTION_MIME_TYPE
# Inherited displayname is `self.name`, which for a DirCollection is the
# full virtual path (e.g. "/sd/40 tracks/") because __init__ sets
# self.name = virdir. WebDAV clients expect a basename, so override it
# with just the leaf name.
leaf = os.path.basename(self.fsname.rstrip('/\\'))
if leaf:
p['displayname'] = leaf
return p
def getMembers(self):