BoxInspect
Changes
index.js 16(+13 -3)
Details
index.js 16(+13 -3)
diff --git a/index.js b/index.js
index fab8cfe..1676d2d 100644
--- a/index.js
+++ b/index.js
@@ -13,10 +13,18 @@ const sdk = new BoxSDK({
// Create a basic API client, which does not automatically refresh the access token
const client = sdk.getBasicClient(process.env.DEV_TOKEN);
-const getChildFolders = async (id) => {
+const rootFolders = []
+const getFolders = async (id) => {
const r = await client.folders.get(id)
const folderIds = r.item_collection.entries.filter(f => f.type === 'folder').map(f => f.id)
- return folderIds
+ if (folderIds.length === 0) {
+ rootFolders.push(id)
+ return
+ } else {
+ for (let folderId of folderIds) {
+ await getFolders(folderId)
+ }
+ }
}
const getFolderContents = async (id) => {
@@ -34,7 +42,9 @@ const getFolderContents = async (id) => {
}
const main = async (parentFolder) => {
- const folderIds = await getChildFolders(parentFolder)
+ await getFolders(parentFolder)
+
+ const folderIds = [...rootFolders]
const files = []
for (let folderId of folderIds) {
let contents = await getFolderContents(folderId)