use second request for paging instead of expand children

This commit is contained in:
spencerwooo
2021-09-04 18:47:31 +01:00
parent 97f4250a57
commit 091e97f211
2 changed files with 31 additions and 21 deletions
+14 -4
View File
@@ -112,15 +112,25 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
}
// Normal query selecting and expanding every children in current directory
const { data } = await axios.get(requestUrl, {
// Querying current path identity (file or folder) and follow up query childrens in folder
const { data: identityData } = await axios.get(requestUrl, {
headers: { Authorization: `Bearer ${accessToken}` },
params: {
select: '@microsoft.graph.downloadUrl,name,size,id,lastModifiedDateTime,folder,file',
expand: 'children(select=@content.downloadUrl,name,lastModifiedDateTime,eTag,size,id,folder,file)',
},
})
res.status(200).json({ path, data })
if ('folder' in identityData) {
const { data: folderData } = await axios.get(`${requestUrl}:/children`, {
headers: { Authorization: `Bearer ${accessToken}` },
params: {
select: '@microsoft.graph.downloadUrl,name,size,id,lastModifiedDateTime,folder,file',
},
})
res.status(200).json({ path, identityData, folderData })
return
}
res.status(200).json({ path, identityData })
return
}