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
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
5 changes: 3 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,9 @@ 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()
const listFilesResult = yield webdav.listFiles(space, { path, fileId })
const resources = listFilesResult.children
let currentFolder = listFilesResult.resource
lookacat marked this conversation as resolved.
Show resolved Hide resolved
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 = {
resource: {} as Resource,
children: [] as Resource[]
} as ListFilesResult
lookacat marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Up @@ -63,9 +63,10 @@ export function useAppFolderHandling({
})

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

if (resources[0].type === 'file') {
store.commit('Files/LOAD_FILES', {
Expand Down