diff --git a/package.json b/package.json index 9a3e093..af47c59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuclia-sync-agent-app", - "version": "1.2.5", + "version": "1.2.6", "description": "This is a Nuclia Sync Agent App", "main": "build/index.js", "scripts": { diff --git a/server/CHANGELOG.md b/server/CHANGELOG.md index 7e13d9d..b54855c 100644 --- a/server/CHANGELOG.md +++ b/server/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.2.6 (2024-03-27) + +- Fix path when retrieving folders. + # 1.2.5 (2024-03-22) - Add RSS connector diff --git a/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts b/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts index 83d1e66..0883418 100644 --- a/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/gdrive.connector.ts @@ -92,7 +92,49 @@ export class GDriveImpl extends OAuthBaseConnector implements IConnector { } getFolders(query?: string | undefined): Observable { - return this._getItems(query, '', true); + return this._getItems(query, '', true).pipe( + map((results) => { + const folders = results.items; + const getFolder = (folderId: string) => { + return folders.find((folder) => folder.originalId === folderId); + }; + const parents = folders.reduce( + (acc, folder) => { + if (folder.parents) { + acc[folder.originalId] = folder.parents[0]; + } + return acc; + }, + {} as { [key: string]: string }, + ); + const getFolderPath = (folderId: string | undefined) => { + if (!folderId) { + return []; + } + let path: string[] = []; + let currentFolder = getFolder(folderId); + while (currentFolder) { + path = [currentFolder.title, ...path]; + if (!parents[currentFolder.originalId]) { + break; + } + currentFolder = getFolder(parents[currentFolder.originalId]); + } + return path; + }; + const foldersWithPath = folders.map((folder) => ({ + ...folder, + metadata: { + ...folder.metadata, + path: getFolderPath(folder.parents?.[0]).join('/'), + }, + })); + return { + ...results, + items: foldersWithPath, + }; + }), + ); } getFiles(query?: string): Observable { diff --git a/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts b/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts index 87d1498..c109bf2 100644 --- a/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts +++ b/server/src/logic/connector/infrastructure/connectors/onedrive.connector.ts @@ -230,7 +230,9 @@ export class OneDriveImpl extends OAuthBaseConnector implements IConnector { uuid: item.id, title: item.name, originalId: item.id, - metadata: {}, + metadata: { + path: item.parentReference.path, + }, status: FileStatus.PENDING, isFolder: true, };