1919 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2020 *
2121 */
22+ import type { ContentsWithRoot } from '@nextcloud/files'
2223import type { FileStat , ResponseDataDetailed } from 'webdav'
2324import type { TagWithId } from '../types'
2425
25- import { Folder , type ContentsWithRoot , Permission , getDavNameSpaces , getDavProperties } from '@nextcloud/files'
26- import { generateRemoteUrl } from '@nextcloud/router'
2726import { getCurrentUser } from '@nextcloud/auth'
28-
27+ import { Folder , Permission , getDavNameSpaces , getDavProperties , davGetClient , davResultToNode , davRemoteURL , davRootPath } from '@nextcloud/files'
2928import { fetchTags } from './api'
30- import { getClient } from '../../../files/src/services/WebdavClient'
31- import { resultToNode } from '../../../files/src/services/Files'
29+
30+ const rootPath = '/systemtags'
31+
32+ const client = davGetClient ( )
33+ const resultToNode = ( node : FileStat ) => davResultToNode ( node )
3234
3335const formatReportPayload = ( tagId : number ) => `<?xml version="1.0"?>
3436<oc:filter-files ${ getDavNameSpaces ( ) } >
3537 <d:prop>
3638 ${ getDavProperties ( ) }
3739 </d:prop>
38- <oc:filter-rules>
39- <oc:systemtag>${ tagId } </oc:systemtag>
40- </oc:filter-rules>
40+ <oc:filter-rules>
41+ <oc:systemtag>${ tagId } </oc:systemtag>
42+ </oc:filter-rules>
4143</oc:filter-files>`
4244
4345const tagToNode = function ( tag : TagWithId ) : Folder {
4446 return new Folder ( {
4547 id : tag . id ,
46- source : generateRemoteUrl ( 'dav/systemtags/' + tag . id ) ,
47- owner : getCurrentUser ( ) ?. uid as string ,
48- root : '/systemtags' ,
48+ source : `${ davRemoteURL } ${ rootPath } /${ tag . id } ` ,
49+ owner : String ( getCurrentUser ( ) ?. uid ?? 'anonymous' ) ,
50+ root : rootPath ,
51+ displayname : tag . displayName ,
4952 permissions : Permission . READ ,
5053 attributes : {
5154 ...tag ,
@@ -62,24 +65,24 @@ export const getContents = async (path = '/'): Promise<ContentsWithRoot> => {
6265 return {
6366 folder : new Folder ( {
6467 id : 0 ,
65- source : generateRemoteUrl ( 'dav/systemtags' ) ,
68+ source : ` ${ davRemoteURL } ${ rootPath } ` ,
6669 owner : getCurrentUser ( ) ?. uid as string ,
67- root : '/systemtags' ,
70+ root : rootPath ,
6871 permissions : Permission . NONE ,
6972 } ) ,
7073 contents : tagsCache . map ( tagToNode ) ,
7174 }
7275 }
7376
74- const tagId = parseInt ( path . replace ( '/' , '' ) , 10 )
77+ const tagId = parseInt ( path . split ( '/' , 2 ) [ 0 ] )
7578 const tag = tagsCache . find ( tag => tag . id === tagId )
7679
7780 if ( ! tag ) {
7881 throw new Error ( 'Tag not found' )
7982 }
8083
8184 const folder = tagToNode ( tag )
82- const contentsResponse = await getClient ( ) . getDirectoryContents ( '/' , {
85+ const contentsResponse = await client . getDirectoryContents ( davRootPath , {
8386 details : true ,
8487 // Only filter favorites if we're at the root
8588 data : formatReportPayload ( tagId ) ,
0 commit comments