def _format_url()

in connectors/sharepoint/sharepoint_data_reader.py [0:0]


    def _format_url(site_id: str, drive_id: str, folder_path: str = None) -> str:
        """
        Formats the URL for accessing a nested site drive in Microsoft Graph.

        :param site_id: The site ID in Microsoft Graph.
        :param drive_id: The drive ID in Microsoft Graph.
        :param folder_path: path to the folder within the drive, can include subfolders.
            The format should follow '/folder/subfolder1/subfolder2/'. For example,
            '/test/test1/test2/' to access nested folders.
        :return: The formatted URL.
        """
        # If folder_path is None, empty, or just "/" then return the root folder URL.
        if not folder_path or folder_path.strip() == "/":
            return f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{drive_id}/root/"
        
        # Otherwise, remove any trailing slashes and format the URL for a subfolder.
        folder_path_formatted = folder_path.rstrip("/")
        return f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{drive_id}/root:{folder_path_formatted}:/"