Skip to content

Commit

Permalink
add missing path on folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ebrehault committed Mar 27, 2024
1 parent 3dc4086 commit 1a0da83
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
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 1a0da83

Please sign in to comment.