aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/services/FileInfo.js
blob: 4e08cdb234dd7c89471861d221cf4e97c81cc396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import axios from '@nextcloud/axios'
import { davGetDefaultPropfind } from '@nextcloud/files'

/**
 * @param {any} url -
 */
export default async function(url) {
	const response = await axios({
		method: 'PROPFIND',
		url,
		data: davGetDefaultPropfind(),
	})

	// TODO: create new parser or use cdav-lib when available
	const file = OC.Files.getClient()._client.parseMultiStatus(response.data)
	// TODO: create new parser or use cdav-lib when available
	const fileInfo = OC.Files.getClient()._parseFileInfo(file[0])

	// TODO remove when no more legacy backbone is used
	fileInfo.get = (key) => fileInfo[key]
	fileInfo.isDirectory = () => fileInfo.mimetype === 'httpd/unix-directory'

	return fileInfo
}