From 7ae8489f200f0d2d1bb126513e0db5ed8cd391a4 Mon Sep 17 00:00:00 2001 From: mit <1mitccc@gmail.com> Date: Tue, 17 Sep 2024 23:04:54 +0530 Subject: [PATCH] Consider drive root to be a folder when syncing onedrive/sharepoint --- .../folder/services/onedrive/index.ts | 15 ++++++++++++++- .../folder/services/onedrive/types.ts | 2 ++ .../folder/services/sharepoint/index.ts | 17 +++++++++++++++-- .../folder/services/sharepoint/types.ts | 2 ++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/api/src/filestorage/folder/services/onedrive/index.ts b/packages/api/src/filestorage/folder/services/onedrive/index.ts index f02db9f95..589480e2e 100644 --- a/packages/api/src/filestorage/folder/services/onedrive/index.ts +++ b/packages/api/src/filestorage/folder/services/onedrive/index.ts @@ -83,7 +83,20 @@ export class OnedriveService implements IFolderService { }, }); - let result = [], + // get root folder + const rootFolderData = await axios.get( + `${connection.account_url}/v1.0/me/drive/root`, + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }, + ); + + let result = [rootFolderData.data], depth = 0, batch = [remote_folder_id]; diff --git a/packages/api/src/filestorage/folder/services/onedrive/types.ts b/packages/api/src/filestorage/folder/services/onedrive/types.ts index 725a92f46..3d9448a19 100644 --- a/packages/api/src/filestorage/folder/services/onedrive/types.ts +++ b/packages/api/src/filestorage/folder/services/onedrive/types.ts @@ -55,6 +55,8 @@ export interface OnedriveFolderInput { readonly createdBy?: IdentitySet; /** Identity of the user, device, and application that last modified the item. Read-only. */ readonly lastModifiedBy?: IdentitySet; + /** If this property is non-null, it indicates that the driveItem is the top-most driveItem in the drive. */ + readonly root?: any; } /** diff --git a/packages/api/src/filestorage/folder/services/sharepoint/index.ts b/packages/api/src/filestorage/folder/services/sharepoint/index.ts index c2ee70a7b..b83c4bf40 100644 --- a/packages/api/src/filestorage/folder/services/sharepoint/index.ts +++ b/packages/api/src/filestorage/folder/services/sharepoint/index.ts @@ -80,7 +80,20 @@ export class SharepointService implements IFolderService { }, }); - let result = [], + // get root folder + const rootFolderData = await axios.get( + `${connection.account_url}/drive/root`, + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${this.cryptoService.decrypt( + connection.access_token, + )}`, + }, + }, + ); + + let result = [rootFolderData.data], depth = 0, batch = [remote_folder_id]; @@ -104,7 +117,7 @@ export class SharepointService implements IFolderService { }, ); - // Add permissions (shared link is also included in permissions in one-drive) + // Add permissions (shared link is also included in permissions in SharePoint) // await Promise.all( // resp.data.value.map(async (driveItem) => { // const resp = await axios.get( diff --git a/packages/api/src/filestorage/folder/services/sharepoint/types.ts b/packages/api/src/filestorage/folder/services/sharepoint/types.ts index 5bf8784a4..dcd4a7afb 100644 --- a/packages/api/src/filestorage/folder/services/sharepoint/types.ts +++ b/packages/api/src/filestorage/folder/services/sharepoint/types.ts @@ -55,6 +55,8 @@ export interface SharepointFolderInput { readonly createdBy?: IdentitySet; /** Identity of the user, device, and application that last modified the item. Read-only. */ readonly lastModifiedBy?: IdentitySet; + /** If this property is non-null, it indicates that the driveItem is the top-most driveItem in the drive. */ + readonly root?: any; } /**