nextcloud-files
nextcloud-files copied to clipboard
Should NodeData.root be a required property?
https://github.com/nextcloud-libraries/nextcloud-files/blob/d3ae6caa48aa41be333965a4b85ac1059088e9b8/lib/files/nodeData.ts#L68-L73
Example URI: https://domain.com/remote.php/dav/files/emma/test/picture.jpeg
- scheme + host:
https://domain.com - dav service:
/remote.php/dav - root:
/files/emma - dirname:
/test - basename:
picture.jpeg
This would be the expected result, according to what I know.
The current implementation uses dirname + split on the dav service to set the root.
For the example URI
'https://domain.com/remote.php/dav/files/emma/test'.split(/(remote|public)\.php\/(web)?dav/i).pop()/files/emma/test
That looks wrong :worried:
Test case:
describe('Is the root properly detected?', () => {
test('File', () => {
const file = new File({
source: 'https://domain.com/remote.php/dav/files/emma/test/emma.jpeg',
encodedSource: 'https://domain.com/remote.php/dav/files/emma/test/emma.jpeg',
mime: 'image/jpeg',
owner: 'emma',
})
expect(file.root).toBe('/files/emma')
expect(file.dirname).toBe('/test')
expect(file.path).toBe('/test/emma.jpeg')
})
test('Folder', () => {
const file = new Folder({
source: 'https://domain.com/remote.php/dav/files/emma/test/test2',
encodedSource: 'https://domain.com/remote.php/dav/files/emma/test/test2',
owner: 'emma',
})
expect(file.root).toBe('/files/emma')
expect(file.dirname).toBe('/test')
expect(file.path).toBe('/test/test2')
})
})
I agree that we should make it required, but that would need a breaking v4 release IMHO.