Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enh: Migrate to use webdav v5 and @nextcloud/files for DAV handling
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux authored and artonge committed Apr 9, 2025
commit 4a65c8c1b7b8f5016d1189a0f4eb403be77bfaee
2 changes: 1 addition & 1 deletion src/components/Albums/CollaboratorsSelectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export default {
await this.updateAlbumCollaborators()
await this.fetchCollection(
this.albumFileName,
['<nc:location />', '<nc:dateRange />', '<nc:collaborators />']
['<nc:location />', '<nc:dateRange />', '<nc:collaborators />'],
)
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/FilesListViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { NcEmptyContent, NcLoadingIcon } from '@nextcloud/vue'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'

import TiledLayout from '../components/TiledLayout/TiledLayout.vue'
import { fetchFile } from '../services/fileFetcher.js'
import { fetchFile } from '../services/fileFetcher.ts'
import VirtualScrolling from '../components/VirtualScrolling.vue'
import EmptyBox from '../assets/Illustrations/empty.svg'

Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { generateFilePath } from '@nextcloud/router'
import { getRequestToken } from '@nextcloud/auth'
import { registerDavProperty } from '@nextcloud/files/dav'
import { sync } from 'vuex-router-sync'
import { translate, translatePlural } from '@nextcloud/l10n'
import Vue from 'vue'
Expand All @@ -29,6 +30,11 @@ sync(store, router)
Vue.prototype.t = translate
Vue.prototype.n = translatePlural

registerDavProperty('nc:metadata-photos-size')
registerDavProperty('nc:metadata-files-live-photo')
registerDavProperty('nc:metadata-blurhash')
registerDavProperty('nc:metadata-photos-original_date_time')

// TODO: remove when we have a proper fileinfo standalone library
// original scripts are loaded from
// https://github.com/nextcloud/server/blob/5bf3d1bb384da56adbf205752be8f840aac3b0c5/lib/private/legacy/template.php#L120-L122
Expand Down
2 changes: 2 additions & 0 deletions src/mixins/FetchCollectionsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { mapActions } from 'vuex'

import AbortControllerMixin from './AbortControllerMixin.js'
import { fetchCollections } from '../services/collectionFetcher.js'
import logger from '../services/logger.js'

export default {
name: 'FetchCollectionsMixin',
Expand Down Expand Up @@ -53,6 +54,7 @@ export default {
} else {
this.errorFetchingCollections = error
}
logger.error('Error fetching collections:', { error })
} finally {
this.loadingCollections = false
}
Expand Down
39 changes: 22 additions & 17 deletions src/mixins/FetchFacesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { mapActions, mapGetters } from 'vuex'

import { showError } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
import { mapActions, mapGetters } from 'vuex'
import he from 'he'

import client from '../services/DavClient.js'
import logger from '../services/logger.js'
import DavRequest from '../services/DavRequest.js'
import { genFileInfo } from '../utils/fileUtils.js'
import logger from '../services/logger.js'
import AbortControllerMixin from './AbortControllerMixin.js'
import he from 'he'
import { davClient } from '../services/DavClient.ts'
import { getPropFind } from '../services/DavRequest.ts'

const recognizeDAVProps = [
'nc:face-detections',
'nc:face-preview-image',
'nc:realpath',
]

export default {
name: 'FetchFacesMixin',
Expand Down Expand Up @@ -59,8 +64,8 @@ export default {
this.loadingFaces = true
this.errorFetchingFaces = null

const { data: faces } = await client.getDirectoryContents(`/recognize/${getCurrentUser()?.uid}/faces/`, {
data: DavRequest,
const { data: faces } = await davClient.getDirectoryContents(`/recognize/${getCurrentUser()?.uid}/faces/`, {
data: getPropFind(recognizeDAVProps),
details: true,
signal: this.abortController.signal,
})
Expand Down Expand Up @@ -94,13 +99,13 @@ export default {
this.errorFetchingFiles = null
this.loadingFiles = true

let { data: fetchedFiles } = await client.getDirectoryContents(
let { data: fetchedFiles } = await davClient.getDirectoryContents(
`/recognize/${getCurrentUser()?.uid}/faces/${faceName}`,
{
data: DavRequest,
data: getPropFind(recognizeDAVProps),
details: true,
signal: this.abortController.signal,
}
},
)

fetchedFiles = fetchedFiles
Expand Down Expand Up @@ -146,13 +151,13 @@ export default {
this.errorFetchingFiles = null
this.loadingFiles = true

let { data: fetchedFiles } = await client.getDirectoryContents(
let { data: fetchedFiles } = await davClient.getDirectoryContents(
`/recognize/${getCurrentUser()?.uid}/unassigned-faces`,
{
data: DavRequest,
data: getPropFind(recognizeDAVProps),
details: true,
signal: this.abortController.signal,
}
},
)

fetchedFiles = fetchedFiles
Expand Down Expand Up @@ -187,13 +192,13 @@ export default {

async fetchUnassignedFacesCount() {
try {
const { data: unassignedFacesRoot } = await client.stat(
const { data: unassignedFacesRoot } = await davClient.stat(
`/recognize/${getCurrentUser()?.uid}/unassigned-faces`,
{
data: DavRequest,
data: getPropFind(recognizeDAVProps),
details: true,
signal: this.abortController.signal,
}
},
)

const count = Number(unassignedFacesRoot.props.nbItems)
Expand Down
12 changes: 8 additions & 4 deletions src/mixins/FetchFilesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { davGetClient, davRootPath } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { davRootPath } from '@nextcloud/files'
import { joinPaths } from '@nextcloud/paths'

import { davClient } from '../services/DavClient.ts'
import logger from '../services/logger.js'
import getPhotos from '../services/PhotoSearch.js'
import SemaphoreWithPriority from '../utils/semaphoreWithPriority.js'
Expand Down Expand Up @@ -74,7 +77,7 @@ export default {
this.fetchedFileIds.push(
...fileIds
.map((fileId) => fileId.toString())
.filter((fileId) => !blacklist.includes(fileId))
.filter((fileId) => !blacklist.includes(fileId)),
)

this.$store.dispatch('appendFiles', fetchedFiles)
Expand All @@ -91,7 +94,7 @@ export default {
}
logger.debug(`The ${source} folder does not exist, creating it.`)
try {
await davGetClient().createDirectory(joinPaths(davRootPath, source))
await davClient.createDirectory(joinPaths(davRootPath, source))
this.resetFetchFilesState()
return []
} catch (error) {
Expand All @@ -106,7 +109,8 @@ export default {
}

// cancelled request, moving on...
logger.error('Error fetching files', { error })
showError(t('photos', 'Error fetching files'))
logger.error(error)
} finally {
this.loadingFiles = false
this.fetchSemaphore.release(fetchSemaphoreSymbol)
Expand Down
12 changes: 6 additions & 6 deletions src/services/Albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import moment from '@nextcloud/moment'
import { translate as t } from '@nextcloud/l10n'

import defaultClient from '../services/DavClient.js'
import logger from '../services/logger.js'
import DavRequest from '../services/DavRequest.js'
import { genFileInfo } from '../utils/fileUtils.js'
import { davClient } from './DavClient.ts'
import { getPropFind } from './DavRequest.ts'

/**
* @typedef {object} Album
Expand Down Expand Up @@ -51,7 +51,7 @@ function getDavRequest(extraProps = '') {
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
* @return {Promise<Album|null>}
*/
export async function fetchAlbum(path, options, extraProps = '', client = defaultClient) {
export async function fetchAlbum(path, options, extraProps = '', client = davClient) {
try {
const response = await client.stat(path, {
data: getDavRequest(extraProps),
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function fetchAlbum(path, options, extraProps = '', client = defaul
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
* @return {Promise<Album[]>}
*/
export async function fetchAlbums(path, options, extraProps = '', client = defaultClient) {
export async function fetchAlbums(path, options, extraProps = '', client = davClient) {
try {
const response = await client.getDirectoryContents(path, {
data: getDavRequest(extraProps),
Expand Down Expand Up @@ -147,10 +147,10 @@ function formatAlbum(album) {
* @param {import('webdav').WebDAVClient} client - The DAV client to use.
* @return {Promise<Array>}
*/
export async function fetchAlbumContent(path, options, client = defaultClient) {
export async function fetchAlbumContent(path, options, client = davClient) {
try {
const response = await client.getDirectoryContents(path, {
data: DavRequest,
data: getPropFind(),
details: true,
...options,
})
Expand Down
24 changes: 0 additions & 24 deletions src/services/DavClient.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/services/DavClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { WebDAVClient } from 'webdav'
import { getClient } from '@nextcloud/files/dav'

export const davClient: WebDAVClient = getClient()
35 changes: 0 additions & 35 deletions src/services/DavRequest.js

This file was deleted.

38 changes: 38 additions & 0 deletions src/services/DavRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getDavProperties } from '@nextcloud/files/dav'

/**
* Used to cache the props
*/
let props: string|null = null

/**
* Get the default WebDAV properties
* This is cached for performance reasons
*/
export const getDefaultDavProps = () => {
if (props === null) {
props = getDavProperties()
}
return props
}

/**
* @param extraProps - Extra properties to add to the DAV request.
*/
export function getPropFind(extraProps: string[] = []): string {
return `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:nc="http://nextcloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>
${getDefaultDavProps()}
${extraProps.join('\n')}
</d:prop>
</d:propfind>`
}
27 changes: 0 additions & 27 deletions src/services/FileInfo.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/services/FolderInfo.js

This file was deleted.

Loading