From 9ad71b267557be39b8527b6c5fda204e37ca804a Mon Sep 17 00:00:00 2001 From: myl7 Date: Mon, 1 Nov 2021 18:35:34 +0800 Subject: [PATCH] fix 500 when setting root as public root When listing root children, the path should omit a colon Ref https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_children?view=odsp-graph-online#list-children-in-the-root-of-the-current-users-drive --- pages/api/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pages/api/index.ts b/pages/api/index.ts index 37d8a37..5c87dac 100644 --- a/pages/api/index.ts +++ b/pages/api/index.ts @@ -91,8 +91,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } } + const requestPath = encodePath(path) // Handle response from OneDrive API - const requestUrl = `${apiConfig.driveApi}/root${encodePath(path)}` + const requestUrl = `${apiConfig.driveApi}/root${requestPath}` + // Whether path is root, which requires some special treatment + const isRoot = requestPath === '' // Go for file raw download link and query with only temporary link parameter if (raw) { @@ -124,7 +127,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }) if ('folder' in identityData) { - const { data: folderData } = await axios.get(`${requestUrl}:/children`, { + const { data: folderData } = await axios.get(`${requestUrl}${isRoot ? '': ':'}/children`, { headers: { Authorization: `Bearer ${accessToken}` }, params: next ? {