Passed
Pull Request — master (#555)
by John
03:00
created

src/services/FolderInfo.js   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 27
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0
1
/**
2
 * @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
3
 *
4
 * @author John Molakvoæ <[email protected]>
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
23
import client from './DavClient'
24
import request from './DavRequest'
25
26
/**
27
 * List files from a folder and filter out unwanted mimes
28
 *
29
 * @param {String} path the path relative to the user root
30
 * @returns {Array} the file list
31
 */
32
export default async function(path) {
33
	// getDirectoryContents doesn't accept / for root
34
	const fixedPath = path === '/' ? '' : path
35
36
	// fetch listing
37
	const response = await client.stat(fixedPath, {
38
		data: request,
39
		details: true
40
	})
41
42
	const entry = response.data
43
	return Object.assign({
44
		id: parseInt(entry.props.fileid),
45
		isFavorite: entry.props.favorite !== '0',
46
		hasPreview: entry.props['has-preview'] !== 'false'
47
	}, entry)
48
49
}
50