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

src/services/PhotoSearch.js   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 56
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 56
rs 10
wmc 1
mnd 0
bc 0
fnc 1
bpm 0
cpm 1
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 { getCurrentUser } from '@nextcloud/auth'
25
26
/**
27
 * List files from a folder and filter out unwanted mimes
28
 *
29
 * @returns {Array} the file list
30
 */
31
export default async function() {
32
	// fetch listing
33
	const response = await client.customRequest('', {
34
		method: 'SEARCH',
35
		headers: {
36
			'content-Type': 'text/xml'
37
		},
38
		url: '/remote.php/dav/',
39
		data: `<?xml version="1.0" encoding="UTF-8"?>
40
<d:searchrequest xmlns:d="DAV:"
41
	xmlns:oc="http://owncloud.org/ns"
42
	xmlns:nc="http://nextcloud.org/ns"
43
	xmlns:ocs="http://open-collaboration-services.org/ns">
44
	<d:basicsearch>
45
		<d:select>
46
			<d:prop>
47
				<d:getlastmodified />
48
				<d:getetag />
49
				<d:getcontenttype />
50
				<oc:fileid />
51
				<d:getcontentlength />
52
				<nc:has-preview />
53
				<oc:favorite />
54
				<d:resourcetype />
55
			</d:prop>
56
		</d:select>
57
		<d:from>
58
			<d:scope>
59
				<d:href>/files/${getCurrentUser().uid}/</d:href>
60
				<d:depth>infinity</d:depth>
61
			</d:scope>
62
		</d:from>
63
		<d:where>
64
			<d:like>
65
				<d:prop>
66
					<d:getcontenttype/>
67
				</d:prop>
68
				<d:literal>image/jpeg</d:literal>
69
			</d:like>
70
		</d:where>
71
		<d:orderby/>
72
	</d:basicsearch>
73
</d:searchrequest>` })
74
75
	const entry = response.data
76
	console.info(entry)
77
78
}
79