fix: PROPFIND returns correct file size and href for WebDAV clients

- Read FileSizeBytes instead of non-existent File-Size metadata field,
  so getcontentlength reports actual bytes instead of always 0
- Add /dav prefix to file href so WebDAV clients can GET files at the
  correct path

Fixes files showing as 0B and being unopenable in RaiDrive, Cyberduck,
and Windows mapped drives.
This commit is contained in:
MarSeventh
2026-05-01 20:36:07 +08:00
parent 18b2db1224
commit c2e4de5b8c
+2 -2
View File
@@ -324,6 +324,6 @@ function createCollectionXml(path) {
function createFileXml(file) {
const now = new Date().toUTCString();
const fileSize = file.metadata && file.metadata['File-Size'] ? file.metadata['File-Size'] : "0";
return `<D:response><D:href>${encodeURI(`/${file.name}`)}</D:href><D:propstat><D:prop><D:displayname>${file.name.split('/').pop()}</D:displayname><D:resourcetype/><D:creationdate>${now}</D:creationdate><D:getlastmodified>${now}</D:getlastmodified><D:getcontentlength>${fileSize}</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>`;
const fileSize = file.metadata && file.metadata['FileSizeBytes'] ? file.metadata['FileSizeBytes'] : "0";
return `<D:response><D:href>${encodeURI(`/dav/${file.name}`)}</D:href><D:propstat><D:prop><D:displayname>${file.name.split('/').pop()}</D:displayname><D:resourcetype/><D:creationdate>${now}</D:creationdate><D:getlastmodified>${now}</D:getlastmodified><D:getcontentlength>${fileSize}</D:getcontentlength></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>`;
}