fix(files_sharing): Normalize dir type to folder for federated shares

The backend returns type 'dir' for folders (from FileInfo::TYPE_FOLDER),
but the frontend expects 'folder'. This mismatch caused federated shared
folders to display incorrectly as files in the "Shared with you" view.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
nfebe 2025-12-10 21:16:12 +07:00
parent 186b12b718
commit 0c2df7ff49
2 changed files with 51 additions and 1 deletions

@ -313,6 +313,25 @@ describe('SharingService share to Node mapping', () => {
accepted: false,
}
const remoteFolderAccepted = {
mimetype: 'httpd/unix-directory',
mtime: 1688721600,
permissions: 31,
type: 'dir',
file_id: 5678,
id: 5,
share_type: ShareType.User,
parent: null,
remote: 'http://example.com',
remote_id: '12346',
share_token: 'share-token-folder',
name: '/testfolder',
mountpoint: '/shares/testfolder',
owner: 'owner-uid',
user: 'sharee-uid',
accepted: true,
}
const tempExternalFile = {
id: 65,
share_type: 0,
@ -457,6 +476,36 @@ describe('SharingService share to Node mapping', () => {
})
})
describe('Remote folder', () => {
test('Accepted with type dir', async () => {
axios.get.mockReturnValueOnce(Promise.resolve({
data: {
ocs: {
data: [remoteFolderAccepted],
},
},
}))
const shares = await getContents(false, true, false, false)
expect(axios.get).toHaveBeenCalledTimes(1)
expect(shares.contents).toHaveLength(1)
const folder = shares.contents[0] as Folder
expect(folder).toBeInstanceOf(Folder)
expect(folder.fileid).toBe(5678)
expect(folder.source).toBe('http://nextcloud.local/remote.php/dav/files/test/shares/testfolder')
expect(folder.owner).toBe('owner-uid')
expect(folder.mime).toBe('httpd/unix-directory')
expect(folder.mtime?.getTime()).toBe(remoteFolderAccepted.mtime * 1000)
expect(folder.size).toBe(undefined)
expect(folder.permissions).toBe(31)
expect(folder.root).toBe('/files/test')
expect(folder.attributes).toBeInstanceOf(Object)
expect(folder.attributes.favorite).toBe(0)
})
})
test('External temp file', async () => {
axios.get.mockReturnValueOnce(Promise.resolve({
data: {

@ -33,7 +33,8 @@ async function ocsEntryToNode(ocsEntry: any): Promise<Folder | File | null> {
// This won't catch files without an extension, but this is the best we can do
ocsEntry.mimetype = mime.getType(ocsEntry.name)
}
ocsEntry.item_type = ocsEntry.type || (ocsEntry.mimetype ? 'file' : 'folder')
const type = ocsEntry.type === 'dir' ? 'folder' : ocsEntry.type
ocsEntry.item_type = type || (ocsEntry.mimetype ? 'file' : 'folder')
// different naming for remote shares
ocsEntry.item_mtime = ocsEntry.mtime