diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 724f048..efd4131 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -123,7 +123,6 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = ) } - const resp = data.data const fileIsImage = (fileName: string) => { const fileExtension = getExtension(fileName) if (hasKey(extensions, fileExtension)) { @@ -134,8 +133,8 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = return false } - if ('folder' in resp) { - const { children } = resp + if ('folderData' in data) { + const { value } = data.folderData // Image preview rendering preparations const imagesInFolder: ImageDecorator[] = [] @@ -146,7 +145,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = let renderReadme = false let readmeFile = null - children.forEach((c: any) => { + value.forEach((c: any) => { if (fileIsImage(c.name)) { imagesInFolder.push({ src: c['@microsoft.graph.downloadUrl'], @@ -218,7 +217,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = /> )} - {children.map((c: any) => ( + {value.map((c: any) => (
= ({ query }) = ) } - if ('file' in resp) { - const downloadUrl = resp['@microsoft.graph.downloadUrl'] - const fileName = resp.name + if ('identityData' in data) { + const { identityData } = data + const downloadUrl = identityData['@microsoft.graph.downloadUrl'] + const fileName = data.identityData.name const fileExtension = fileName.slice(((fileName.lastIndexOf('.') - 1) >>> 0) + 2).toLowerCase() if (hasKey(extensions, fileExtension)) { @@ -297,25 +297,25 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = ) case preview.text: - return + return case preview.code: - return + return case preview.markdown: - return + return case preview.video: - return + return case preview.audio: - return + return case preview.pdf: - return + return case preview.office: - return + return default: return
{fileName}
@@ -326,7 +326,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = <>
@@ -338,7 +338,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = return (
- +
) } diff --git a/pages/api/index.ts b/pages/api/index.ts index efd0679..2e2e728 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -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 }