Skip to content

Commit 34ab707

Browse files
committed
enh: Migrate to use webdav v5 and @nextcloud/files for DAV handling
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent dc24021 commit 34ab707

27 files changed

+172
-290
lines changed

src/components/Albums/CollaboratorsSelectionForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ export default {
349349
await this.updateAlbumCollaborators()
350350
await this.fetchCollection(
351351
this.albumFileName,
352-
['<nc:location />', '<nc:dateRange />', '<nc:collaborators />']
352+
['<nc:location />', '<nc:dateRange />', '<nc:collaborators />'],
353353
)
354354
},
355355

src/components/FilesListViewer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import { NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
8484
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
8585
8686
import TiledLayout from '../components/TiledLayout/TiledLayout.vue'
87-
import { fetchFile } from '../services/fileFetcher.js'
87+
import { fetchFile } from '../services/fileFetcher.ts'
8888
import VirtualScrolling from '../components/VirtualScrolling.vue'
8989
import EmptyBox from '../assets/Illustrations/empty.svg'
9090
import UserConfig from '../mixins/UserConfig.js'

src/mixins/FetchFacesMixin.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
*
2121
*/
2222

23-
import { mapActions, mapGetters } from 'vuex'
24-
2523
import { showError } from '@nextcloud/dialogs'
2624
import { getCurrentUser } from '@nextcloud/auth'
25+
import { mapActions, mapGetters } from 'vuex'
26+
import he from 'he'
2727

28-
import client from '../services/DavClient.js'
29-
import logger from '../services/logger.js'
30-
import DavRequest from '../services/DavRequest.js'
3128
import { genFileInfo } from '../utils/fileUtils.js'
29+
import logger from '../services/logger.js'
3230
import AbortControllerMixin from './AbortControllerMixin.js'
33-
import he from 'he'
31+
import { davClient } from '../services/DavClient.ts'
32+
import { getPropFind } from '../services/DavRequest.ts'
3433

3534
export default {
3635
name: 'FetchFacesMixin',
@@ -76,8 +75,8 @@ export default {
7675
this.loadingFaces = true
7776
this.errorFetchingFaces = null
7877

79-
const { data: faces } = await client.getDirectoryContents(`/recognize/${getCurrentUser()?.uid}/faces/`, {
80-
data: DavRequest,
78+
const { data: faces } = await davClient.getDirectoryContents(`/recognize/${getCurrentUser()?.uid}/faces/`, {
79+
data: getPropFind(),
8180
details: true,
8281
signal: this.abortController.signal,
8382
})
@@ -111,13 +110,13 @@ export default {
111110
this.errorFetchingFiles = null
112111
this.loadingFiles = true
113112

114-
let { data: fetchedFiles } = await client.getDirectoryContents(
113+
let { data: fetchedFiles } = await davClient.getDirectoryContents(
115114
`/recognize/${getCurrentUser()?.uid}/faces/${faceName}`,
116115
{
117-
data: DavRequest,
116+
data: getPropFind(),
118117
details: true,
119118
signal: this.abortController.signal,
120-
}
119+
},
121120
)
122121

123122
fetchedFiles = fetchedFiles
@@ -163,13 +162,13 @@ export default {
163162
this.errorFetchingFiles = null
164163
this.loadingFiles = true
165164

166-
let { data: fetchedFiles } = await client.getDirectoryContents(
165+
let { data: fetchedFiles } = await davClient.getDirectoryContents(
167166
`/recognize/${getCurrentUser()?.uid}/unassigned-faces`,
168167
{
169-
data: DavRequest,
168+
data: getPropFind(),
170169
details: true,
171170
signal: this.abortController.signal,
172-
}
171+
},
173172
)
174173

175174
fetchedFiles = fetchedFiles
@@ -204,13 +203,13 @@ export default {
204203

205204
async fetchUnassignedFacesCount() {
206205
try {
207-
const { data: unassignedFacesRoot } = await client.stat(
206+
const { data: unassignedFacesRoot } = await davClient.stat(
208207
`/recognize/${getCurrentUser()?.uid}/unassigned-faces`,
209208
{
210-
data: DavRequest,
209+
data: getPropFind(),
211210
details: true,
212211
signal: this.abortController.signal,
213-
}
212+
},
214213
)
215214

216215
const count = Number(unassignedFacesRoot.props.nbItems)

src/mixins/FetchFilesMixin.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
*/
2222

23+
import { showError } from '@nextcloud/dialogs'
2324
import logger from '../services/logger.js'
2425
import getPhotos from '../services/PhotoSearch.js'
2526
import SemaphoreWithPriority from '../utils/semaphoreWithPriority.js'
@@ -52,8 +53,8 @@ export default {
5253
/**
5354
* @param {string} path - Path to pass to getPhotos.
5455
* @param {object} options - Options to pass to getPhotos.
55-
* @param {string[]} [blacklist=[]] - Array of ids to filter out.
56-
* @param {boolean} [force=false] - Force fetching even if doneFetchingFiles is true
56+
* @param {string[]} [blacklist] - Array of ids to filter out.
57+
* @param {boolean} [force] - Force fetching even if doneFetchingFiles is true
5758
* @return {Promise<string[]>} - The next batch of data depending on global offset.
5859
*/
5960
async fetchFiles(path = '', options = {}, blacklist = [], force = false) {
@@ -89,7 +90,7 @@ export default {
8990
this.fetchedFileIds.push(
9091
...fileIds
9192
.map((fileId) => fileId.toString())
92-
.filter((fileId) => !blacklist.includes(fileId))
93+
.filter((fileId) => !blacklist.includes(fileId)),
9394
)
9495

9596
this.$store.dispatch('appendFiles', fetchedFiles)
@@ -107,8 +108,8 @@ export default {
107108
}
108109

109110
// cancelled request, moving on...
110-
logger.error('Error fetching files', { error })
111-
console.error(error)
111+
showError(t('photos', 'Error fetching files'))
112+
logger.error(error)
112113
} finally {
113114
this.loadingFiles = false
114115
this.fetchSemaphore.release(fetchSemaphoreSymbol)

src/services/Albums.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import moment from '@nextcloud/moment'
2424
import { translate as t } from '@nextcloud/l10n'
2525

26-
import defaultClient from '../services/DavClient.js'
2726
import logger from '../services/logger.js'
28-
import DavRequest from '../services/DavRequest.js'
2927
import { genFileInfo } from '../utils/fileUtils.js'
28+
import { davClient } from './DavClient.ts'
29+
import { getPropFind } from './DavRequest.ts'
3030

3131
/**
3232
* @typedef {object} Album
@@ -68,7 +68,7 @@ function getDavRequest(extraProps = '') {
6868
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
6969
* @return {Promise<Album|null>}
7070
*/
71-
export async function fetchAlbum(path, options, extraProps = '', client = defaultClient) {
71+
export async function fetchAlbum(path, options, extraProps = '', client = davClient) {
7272
try {
7373
const response = await client.stat(path, {
7474
data: getDavRequest(extraProps),
@@ -96,7 +96,7 @@ export async function fetchAlbum(path, options, extraProps = '', client = defaul
9696
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
9797
* @return {Promise<Album[]>}
9898
*/
99-
export async function fetchAlbums(path, options, extraProps = '', client = defaultClient) {
99+
export async function fetchAlbums(path, options, extraProps = '', client = davClient) {
100100
try {
101101
const response = await client.getDirectoryContents(path, {
102102
data: getDavRequest(extraProps),
@@ -164,10 +164,10 @@ function formatAlbum(album) {
164164
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
165165
* @return {Promise<Array>}
166166
*/
167-
export async function fetchAlbumContent(path, options, client = defaultClient) {
167+
export async function fetchAlbumContent(path, options, client = davClient) {
168168
try {
169169
const response = await client.getDirectoryContents(path, {
170-
data: DavRequest,
170+
data: getPropFind(),
171171
details: true,
172172
...options,
173173
})

src/services/DavClient.js

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
2+
* @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]>
33
*
4-
* @author John Molakvoæ <[email protected]>
4+
* @author Ferdinand Thiessen <[email protected]>
55
*
66
* @license AGPL-3.0-or-later
77
*
@@ -20,25 +20,7 @@
2020
*
2121
*/
2222

23-
import client, { prefixPath } from './DavClient.js'
24-
import request from './DavRequest.js'
25-
import { genFileInfo } from '../utils/fileUtils.js'
23+
import type { WebDAVClient } from 'webdav'
24+
import { davGetClient } from '@nextcloud/files'
2625

27-
/**
28-
* Get a file info
29-
*
30-
* @param {string} path the path relative to the user root
31-
* @return {FileInfo} the file info
32-
*/
33-
export default async function(path) {
34-
// getDirectoryContents doesn't accept / for root
35-
const fixedPath = path === '/' ? '' : path
36-
37-
// fetch listing
38-
const response = await client.stat(prefixPath + fixedPath, {
39-
data: request,
40-
details: true,
41-
})
42-
43-
return genFileInfo(response.data)
44-
}
26+
export const davClient: WebDAVClient = davGetClient()

src/services/DavRequest.js renamed to src/services/DavRequest.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
33
*
44
* @author John Molakvoæ <[email protected]>
5+
* @author Ferdinand Thiessen <[email protected]>
56
*
67
* @license AGPL-3.0-or-later
78
*
@@ -19,7 +20,7 @@
1920
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2021
*
2122
*/
22-
const props = `
23+
export const davProps = `
2324
<d:getcontentlength />
2425
<d:getcontenttype />
2526
<d:getetag />
@@ -39,13 +40,17 @@ const props = `
3940
<nc:nbItems />
4041
`
4142

42-
export { props }
43-
export default `<?xml version="1.0"?>
43+
/**
44+
* @param extraProps - Extra properties to add to the DAV request.
45+
*/
46+
export function getPropFind(extraProps: string[] = []): string {
47+
return `<?xml version="1.0"?>
4448
<d:propfind xmlns:d="DAV:"
4549
xmlns:oc="http://owncloud.org/ns"
4650
xmlns:nc="http://nextcloud.org/ns"
4751
xmlns:ocs="http://open-collaboration-services.org/ns">
4852
<d:prop>
49-
${props}
53+
${[...davProps, ...extraProps].join('')}
5054
</d:prop>
5155
</d:propfind>`
56+
}

src/services/FolderInfo.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)