From cb2766c983988ef2192d259497cc70469999e616 Mon Sep 17 00:00:00 2001 From: tangoyankee Date: Fri, 19 Apr 2024 13:42:50 -0400 Subject: [PATCH] legacy urls for nested files Use the full relative path for files that may be nested within several folders closes #1515 --- server/src/sharepoint/sharepoint.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/src/sharepoint/sharepoint.service.ts b/server/src/sharepoint/sharepoint.service.ts index 989ee87d..323a94bf 100644 --- a/server/src/sharepoint/sharepoint.service.ts +++ b/server/src/sharepoint/sharepoint.service.ts @@ -227,8 +227,9 @@ export class SharepointService { } async getSharepointFileId(driveId: string, relativeUrl: string) { - const filePath = relativeUrl.split("/"); - if (filePath.length < 2) + const filePathSegments = relativeUrl.split("/"); + const filePathSegmentsCount = filePathSegments.length; + if (filePathSegmentsCount < 4) throw new HttpException( { code: "DISPOSITION_ID_PATH", @@ -236,8 +237,12 @@ export class SharepointService { }, HttpStatus.BAD_REQUEST ); - const folderName = filePath[filePath.length - 2]; - const fileName = filePath[filePath.length - 1]; + + const fileName = filePathSegments[filePathSegmentsCount - 1]; + // A file may be nested within several folders. We rejoin the folders into the relative path + const folderName = filePathSegments + .slice(2, filePathSegmentsCount - 1) + .join("/"); const { accessToken } = await this.msalProvider.getGraphClientToken(); const url = `${