FileInfo.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import axios from '@nextcloud/axios'
  23. export default async function(url) {
  24. const response = await axios({
  25. method: 'PROPFIND',
  26. url,
  27. data: `<?xml version="1.0"?>
  28. <d:propfind xmlns:d="DAV:"
  29. xmlns:oc="http://owncloud.org/ns"
  30. xmlns:nc="http://nextcloud.org/ns"
  31. xmlns:ocs="http://open-collaboration-services.org/ns">
  32. <d:prop>
  33. <d:getlastmodified />
  34. <d:getetag />
  35. <d:getcontenttype />
  36. <d:resourcetype />
  37. <oc:fileid />
  38. <oc:permissions />
  39. <oc:size />
  40. <d:getcontentlength />
  41. <nc:has-preview />
  42. <nc:mount-type />
  43. <nc:is-encrypted />
  44. <ocs:share-permissions />
  45. <oc:tags />
  46. <oc:favorite />
  47. <oc:comments-unread />
  48. <oc:owner-id />
  49. <oc:owner-display-name />
  50. <oc:share-types />
  51. </d:prop>
  52. </d:propfind>`
  53. })
  54. // TODO: create new parser or use cdav-lib when available
  55. const file = OCA.Files.App.fileList.filesClient._client.parseMultiStatus(response.data)
  56. // TODO: create new parser or use cdav-lib when available
  57. const fileInfo = OCA.Files.App.fileList.filesClient._parseFileInfo(file[0])
  58. // TODO remove when no more legacy backbone is used
  59. fileInfo.get = (key) => fileInfo[key]
  60. fileInfo.isDirectory = () => fileInfo.mimetype === 'httpd/unix-directory'
  61. return fileInfo
  62. }