Skip to content

Commit

Permalink
fix(FilePicker): Adjust resultToNode as we are bound to legacy `@ne…
Browse files Browse the repository at this point in the history
…xtcloud/files` without fixes

This was fixed in 3.1.0 but we have to use 3.0.0-beta for Nextcloud stable27.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Feb 21, 2024
1 parent 640f2cc commit 78b2af5
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions lib/usables/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'

import { davGetClient, davGetDefaultPropfind, davGetRecentSearch, davRemoteURL, davResultToNode, davRootPath, getFavoriteNodes } from '@nextcloud/files'
import { generateRemoteUrl } from '@nextcloud/router'
import { join } from 'path'
import { dirname, join } from 'path'
import { computed, ref, watch } from 'vue'

/**
Expand Down Expand Up @@ -58,15 +58,37 @@ export const useDAVFiles = function(
const token = (document.getElementById('sharingToken')! as HTMLInputElement).value
const autorization = btoa(`${token}:null`)

return davGetClient(defaultRemoteUrl.value, {
Authorization: `Basic ${autorization}`,
})
const client = davGetClient(defaultRemoteUrl.value)
client.setHeaders({ Authorization: `Basic ${autorization}` })
return client
}

return davGetClient()
})

const resultToNode = (result: FileStat) => davResultToNode(result, defaultRootPath.value, defaultRemoteUrl.value)
const resultToNode = (result: FileStat) => {
const node = davResultToNode(result, defaultRootPath.value, defaultRemoteUrl.value)
// Fixed for @nextcloud/files 3.1.0 but not supported on Nextcloud 27 so patching it
if (isPublicEndpoint.value) {
return new Proxy(node, {
get(node, prop) {
if (prop === 'dirname' || prop === 'path') {
const source = node.source
let path = source.slice(defaultRemoteUrl.value.length)
if (path[0] !== '/') {
path = `/${path}`
}
if (prop === 'dirname') {
return dirname(path)
}
return path
}
return (node as never)[prop]
},
})
}
return node
}

/**
* All queried files
Expand Down

0 comments on commit 78b2af5

Please sign in to comment.