@@ -6,51 +6,28 @@ import type { Folder, Node } from '@nextcloud/files'
6
6
import type { ComputedRef , Ref } from 'vue'
7
7
import type { FileStat , ResponseDataDetailed , SearchResult } from 'webdav'
8
8
9
- import { davGetClient , davGetDefaultPropfind , davGetRecentSearch , davRemoteURL , davResultToNode , davRootPath , getFavoriteNodes } from '@nextcloud/files'
10
- import { generateRemoteUrl } from '@nextcloud/router'
9
+ import { davGetClient , davGetDefaultPropfind , davGetRecentSearch , davResultToNode , davRootPath , getFavoriteNodes } from '@nextcloud/files'
11
10
import { join } from 'path'
12
- import { computed , onMounted , ref , shallowRef , watch } from 'vue'
11
+ import { onMounted , ref , shallowRef , watch } from 'vue'
13
12
import { CancelablePromise } from 'cancelable-promise'
14
13
15
14
/**
16
15
* Handle file loading using WebDAV
17
16
*
18
17
* @param currentView Reference to the current files view
19
18
* @param currentPath Reference to the current files path
20
- * @param isPublicEndpoint True if the public `public.php` WebDAV endpoint should be used instead of `remote.php`
21
19
*/
22
20
export const useDAVFiles = function (
23
21
currentView : Ref < 'files' | 'recent' | 'favorites' > | ComputedRef < 'files' | 'recent' | 'favorites' > ,
24
22
currentPath : Ref < string > | ComputedRef < string > ,
25
- isPublicEndpoint : Ref < boolean > | ComputedRef < boolean > ,
26
23
) {
27
24
28
- const defaultRootPath = computed ( ( ) => isPublicEndpoint . value ? '/' : davRootPath )
29
-
30
- const defaultRemoteUrl = computed ( ( ) => {
31
- if ( isPublicEndpoint . value ) {
32
- return generateRemoteUrl ( 'webdav' ) . replace ( '/remote.php' , '/public.php' )
33
- }
34
- return davRemoteURL
35
- } )
36
-
37
25
/**
38
26
* The WebDAV client
39
27
*/
40
- const client = computed ( ( ) => {
41
- if ( isPublicEndpoint . value ) {
42
- const token = ( document . getElementById ( 'sharingToken' ) ! as HTMLInputElement ) . value
43
- const authorization = btoa ( `${ token } :null` )
44
-
45
- return davGetClient ( defaultRemoteUrl . value , {
46
- Authorization : `Basic ${ authorization } ` ,
47
- } )
48
- }
49
-
50
- return davGetClient ( )
51
- } )
28
+ const client = davGetClient ( )
52
29
53
- const resultToNode = ( result : FileStat ) => davResultToNode ( result , defaultRootPath . value , defaultRemoteUrl . value )
30
+ const resultToNode = ( result : FileStat ) => davResultToNode ( result )
54
31
55
32
const getRecentNodes = ( ) : CancelablePromise < Node [ ] > => {
56
33
const controller = new AbortController ( )
@@ -59,7 +36,7 @@ export const useDAVFiles = function(
59
36
return new CancelablePromise ( async ( resolve , reject , onCancel ) => {
60
37
onCancel ( ( ) => controller . abort ( ) )
61
38
try {
62
- const { data } = await client . value . search ( '/' , {
39
+ const { data } = await client . search ( '/' , {
63
40
signal : controller . signal ,
64
41
details : true ,
65
42
data : davGetRecentSearch ( lastTwoWeek ) ,
@@ -77,16 +54,14 @@ export const useDAVFiles = function(
77
54
return new CancelablePromise ( async ( resolve , reject , onCancel ) => {
78
55
onCancel ( ( ) => controller . abort ( ) )
79
56
try {
80
- const results = await client . value . getDirectoryContents ( ` ${ defaultRootPath . value } ${ currentPath . value } ` , {
57
+ const results = await client . getDirectoryContents ( join ( davRootPath , currentPath . value ) , {
81
58
signal : controller . signal ,
82
59
details : true ,
83
60
data : davGetDefaultPropfind ( ) ,
84
61
} ) as ResponseDataDetailed < FileStat [ ] >
85
62
let nodes = results . data . map ( resultToNode )
86
63
// Hack for the public endpoint which always returns folder itself
87
- if ( isPublicEndpoint . value ) {
88
- nodes = nodes . filter ( ( file ) => file . path !== currentPath . value )
89
- }
64
+ nodes = nodes . filter ( ( file ) => file . path !== currentPath . value )
90
65
resolve ( nodes )
91
66
} catch ( error ) {
92
67
reject ( error )
@@ -120,12 +95,12 @@ export const useDAVFiles = function(
120
95
/**
121
96
* Create a new directory in the current path
122
97
* @param name Name of the new directory
123
- * @return The created directory
98
+ * @return { Promise<Folder> } The created directory
124
99
*/
125
100
async function createDirectory ( name : string ) : Promise < Folder > {
126
101
const path = join ( currentPath . value , name )
127
102
128
- await client . value . createDirectory ( join ( defaultRootPath . value , path ) )
103
+ await client . createDirectory ( join ( davRootPath , path ) )
129
104
const directory = await getFile ( path ) as Folder
130
105
files . value = [ ...files . value , directory ]
131
106
return directory
@@ -137,10 +112,8 @@ export const useDAVFiles = function(
137
112
* @param path The path of the file or folder
138
113
* @param rootPath DAV root path, defaults to '/files/USERID'
139
114
*/
140
- async function getFile ( path : string , rootPath : string | undefined = undefined ) {
141
- rootPath = rootPath ?? defaultRootPath . value
142
-
143
- const { data } = await client . value . stat ( `${ rootPath } ${ path } ` , {
115
+ async function getFile ( path : string , rootPath : string = davRootPath ) {
116
+ const { data } = await client . stat ( join ( rootPath , path ) , {
144
117
details : true ,
145
118
data : davGetDefaultPropfind ( ) ,
146
119
} ) as ResponseDataDetailed < FileStat >
@@ -157,7 +130,7 @@ export const useDAVFiles = function(
157
130
isLoading . value = true
158
131
159
132
if ( currentView . value === 'favorites' ) {
160
- promise . value = getFavoriteNodes ( client . value , currentPath . value , defaultRootPath . value )
133
+ promise . value = getFavoriteNodes ( client , currentPath . value )
161
134
} else if ( currentView . value === 'recent' ) {
162
135
promise . value = getRecentNodes ( )
163
136
} else {
0 commit comments