Skip to content

Instantly share code, notes, and snippets.

@pizzacat83
Created March 6, 2019 13:24
Show Gist options
  • Save pizzacat83/1153581865911eb3715b809354be55ae to your computer and use it in GitHub Desktop.
Save pizzacat83/1153581865911eb3715b809354be55ae to your computer and use it in GitHub Desktop.
const paths = new Map<string, string>();
const getPath = (driveItem: ItemWrapper): string => {
const rec = (driveItem: ItemWrapper): { path: string; valid: boolean } => {
if (paths.has(driveItem.id)) {
return { path: paths.get(driveItem.id), valid: true };
}
if (driveItem.id == rootFolderId) {
return { path: '', valid: true };
}
const parents = driveItem.content.getParents();
while (parents.hasNext()) {
const parent = parents.next();
const id = parent.getId();
const parentWrapper = getDriveItem(id, true, parent);
const res = rec(parentWrapper);
if (res.valid) {
const path =
res.path + '/' + (driveItem.name || (driveItem.name = driveItem.content.getName()));
paths.set(driveItem.id, path);
return { path, valid: true };
} else {
return { path: '', valid: false };
}
}
return { path: '', valid: false };
};
return rec(driveItem).path || driveItem.name || (driveItem.name = driveItem.content.getName());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment