Skip to content

Commit

Permalink
Merge pull request #18 from jbwfu/main
Browse files Browse the repository at this point in the history
Update plugin-sync-configuration-webdav.js
  • Loading branch information
Ayideyia authored Nov 11, 2024
2 parents f0e8e99 + 4193614 commit eed6cb3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions plugins/Generic/plugin-sync-configuration-webdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,24 @@ class WebDAV {
const list = []
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(body, 'application/xml')
const responses = xmlDoc.getElementsByTagName('D:response')
const responses = Array.from(xmlDoc.getElementsByTagName('*')).filter(node => node.tagName.toLowerCase() === 'd:response')
const getTextContent = (element, tagName) => {
const nodes = element.getElementsByTagName('*');
for (let node of nodes) {
if (node.tagName.toLowerCase() === tagName.toLowerCase()) {
return node.textContent;
}
}
}
for (let i = 0; i < responses.length; i++) {
const isCollection = responses[i].getElementsByTagNameNS("DAV:", "resourcetype")[0]?.getElementsByTagNameNS("DAV:", "collection").length > 0;
if (isCollection) continue
list.push({
href: responses[i].getElementsByTagName('D:href')[0].textContent,
displayname: responses[i].getElementsByTagName('D:displayname')[0]?.textContent || '',
lastModified: responses[i].getElementsByTagName('D:getlastmodified')[0]?.textContent || 'N/A',
creationDate: responses[i].getElementsByTagName('D:creationdate')[0]?.textContent || 'N/A'
})
href: getTextContent(responses[i], 'D:href'),
displayname: getTextContent(responses[i], 'D:displayname') || '',
lastModified: getTextContent(responses[i], 'D:getlastmodified') || 'N/A',
creationDate: getTextContent(responses[i], 'D:creationdate') || 'N/A'
});
}
return list
}
Expand Down

0 comments on commit eed6cb3

Please sign in to comment.