Created
March 6, 2019 13:24
-
-
Save pizzacat83/1153581865911eb3715b809354be55ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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