Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[full-ci] Refactor webdav listFiles #7880

Merged
merged 11 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog/unreleased/enhancement-webdav-client
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ We've added webdav support to the `web-client` package. This wraps the existing
handles the differentiation of public link and user-specific webdav requests internally.

https://github.com/owncloud/web/pull/7430
https://github.com/owncloud/web/pull/7880
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ export class ResourceTransfer extends ConflictDialog {
}

const errors = []
const targetFolderResources = await this.clientService.webdav.listFiles(
this.targetSpace,
this.targetFolder
)
const targetFolderResources = (
await this.clientService.webdav.listFiles(this.targetSpace, this.targetFolder)
).children

const resolvedConflicts = await this.resolveAllConflicts(
this.resourcesToMove,
Expand Down
9 changes: 5 additions & 4 deletions packages/web-app-files/src/mixins/actions/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ export default {
let parentResources
if (isSameResource(resources[0], this.currentFolder)) {
const parentPath = dirname(this.currentFolder.path)
parentResources = await (this.$clientService.webdav as WebDAV).listFiles(
space || this.space,
{ path: parentPath }
)
parentResources = (
await (this.$clientService.webdav as WebDAV).listFiles(space || this.space, {
path: parentPath
})
).children
}

const confirmAction = (newName) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/web-app-files/src/mixins/actions/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export default {
existingResources = existingResourcesCache[parentPath]
} else {
try {
existingResources = await this.$clientService.webdav.listFiles(this.space, {
path: parentPath
})
existingResources = existingResources.slice(1)
existingResources = (
await this.$clientService.webdav.listFiles(this.space, {
path: parentPath
})
).children
lookacat marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
missingFolderPaths.push(parentPath)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/web-app-files/src/services/folder/loaderSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export class FolderLoaderSpace implements FolderLoader {
try {
store.commit('Files/CLEAR_CURRENT_FILES_LIST')

const resources = yield webdav.listFiles(space, { path, fileId })
let currentFolder = resources.shift()
let { resource: currentFolder, children: resources } = yield webdav.listFiles(space, {
path,
fileId
})
replaceInvalidFileRoute({ space, resource: currentFolder, path, fileId })

if (path === '/') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../../src/helpers/resource'
import { mockDeep, mockReset } from 'jest-mock-extended'
import { buildSpace, Resource } from 'web-client/src/helpers'
import { ListFilesResult } from 'web-client/src/webdav/listFiles'

const clientServiceMock = mockDeep<ClientService>()
let resourcesToMove
Expand Down Expand Up @@ -74,8 +75,12 @@ describe('resourcesTransfer', () => {
it.each([TransferType.COPY, TransferType.MOVE])(
'should copy / move files without renaming them if no conflicts exist',
async (action: TransferType) => {
const listFilesResult: ListFilesResult = {
resource: {} as Resource,
children: []
}
clientServiceMock.webdav.listFiles.mockReturnValueOnce(
new Promise((resolve) => resolve([] as Resource[]))
new Promise((resolve) => resolve(listFilesResult))
)
const resourcesTransfer = new ResourceTransfer(
sourceSpace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function getWrapper({
$clientService: {
webdav: {
listFiles: jest.fn().mockImplementation(() => {
return []
return { resource: {}, children: [] }
}),
restoreFile: jest.fn().mockImplementation(() => {
if (resolveRestore) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-client/src/webdav/getFileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const GetFileInfoFactory = (
depth: 0,
...options
})
)[0]
).resource
}
}
}
25 changes: 14 additions & 11 deletions packages/web-client/src/webdav/listFiles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { buildResource } from '../helpers/resource'
import { buildResource, Resource } from '../helpers/resource'
import { DavProperties, DavProperty } from './constants'
import {
buildPublicSpaceResource,
isPublicSpaceResource,
Resource,
SpaceResource
} from '../helpers'
import { buildPublicSpaceResource, isPublicSpaceResource, SpaceResource } from '../helpers'
import { WebDavOptions } from './types'
import { urlJoin } from '../utils'

Expand All @@ -20,7 +15,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => {
space: SpaceResource,
{ path, fileId }: { path?: string; fileId?: string | number } = {},
{ depth = 1, davProperties }: ListFilesOptions = {}
): Promise<Resource[]> {
): Promise<ListFilesResult> {
let webDavResources: any[]
if (isPublicSpaceResource(space)) {
webDavResources = await sdk.publicFiles.list(
Expand All @@ -44,9 +39,13 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => {
})
if (!path) {
const [rootFolder, ...children] = webDavResources
return [buildPublicSpaceResource(rootFolder), ...children.map(buildResource)]
return {
resource: buildPublicSpaceResource(rootFolder),
children: children.map(buildResource)
} as ListFilesResult
}
return webDavResources.map(buildResource)
const resources = webDavResources.map(buildResource)
return { resource: resources[0], children: resources.slice(1) } as ListFilesResult
}

const listFilesCorrectedPath = async () => {
Expand All @@ -64,7 +63,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => {
if (fileId && fileId !== resources[0].fileId) {
return listFilesCorrectedPath()
}
return resources
return { resource: resources[0], children: resources.slice(1) } as ListFilesResult
} catch (e) {
if (e.statusCode === 404 && fileId) {
return listFilesCorrectedPath()
Expand All @@ -74,3 +73,7 @@ export const ListFilesFactory = ({ sdk }: WebDavOptions) => {
}
}
}
export interface ListFilesResult {
resource: Resource
children?: Resource[]
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Store } from 'vuex'
import { computed, Ref, ref, unref } from '@vue/composition-api'
import { dirname } from 'path'

import { ClientService } from '../../services'
import { MaybeRef } from '../../utils'

import { ClientService, MaybeRef, useAppFileHandling } from 'web-pkg'
import { Resource } from 'web-client'

import { FileContext } from './types'
import { Route } from 'vue-router'
import { useAppFileHandling } from './useAppFileHandling'
import { useFileRouteReplace } from '../router/useFileRouteReplace'
import { DavProperty } from '../../../../web-client/src/webdav/constants'
import { DavProperty } from 'web-client/src/webdav/constants'
import { useAuthService } from '../authContext/useAuthService'

interface AppFolderHandlingOptions {
Expand Down Expand Up @@ -63,19 +58,19 @@ export function useAppFolderHandling({
})

const path = dirname(pathResource.path)
const resources = await webdav.listFiles(space, {
const { resource, children } = await webdav.listFiles(space, {
path
})

if (resources[0].type === 'file') {
if (resource.type === 'file') {
store.commit('Files/LOAD_FILES', {
currentFolder: resources[0],
files: [resources[0]]
currentFolder: resource,
files: [resource]
})
} else {
store.commit('Files/LOAD_FILES', {
currentFolder: resources[0],
files: resources.slice(1)
currentFolder: resource,
files: children
})
}
} catch (error) {
Expand Down