Skip to content

Commit

Permalink
add missing path on folders (#35)
Browse files Browse the repository at this point in the history
* add missing path on folders

* version
  • Loading branch information
ebrehault authored Mar 27, 2024
1 parent 3dc4086 commit 841dc60
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.2.6 (2024-03-27)

- Fix path when retrieving folders.

# 1.2.5 (2024-03-22)

- Add RSS connector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,49 @@ export class GDriveImpl extends OAuthBaseConnector implements IConnector {
}

getFolders(query?: string | undefined): Observable<SearchResults> {
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<SearchResults> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 841dc60

Please sign in to comment.