mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-07-13 04:11:48 +08:00
feat: add pagination support for Notion search (#11194)
This commit is contained in:
parent
a67b0d4771
commit
56c2d1cc55
@ -221,15 +221,29 @@ class NotionOAuth(OAuthDataSource):
|
|||||||
return pages
|
return pages
|
||||||
|
|
||||||
def notion_page_search(self, access_token: str):
|
def notion_page_search(self, access_token: str):
|
||||||
data = {"filter": {"value": "page", "property": "object"}}
|
results = []
|
||||||
headers = {
|
next_cursor = None
|
||||||
"Content-Type": "application/json",
|
has_more = True
|
||||||
"Authorization": f"Bearer {access_token}",
|
|
||||||
"Notion-Version": "2022-06-28",
|
while has_more:
|
||||||
}
|
data = {
|
||||||
response = requests.post(url=self._NOTION_PAGE_SEARCH, json=data, headers=headers)
|
"filter": {"value": "page", "property": "object"},
|
||||||
response_json = response.json()
|
**({"start_cursor": next_cursor} if next_cursor else {}),
|
||||||
results = response_json.get("results", [])
|
}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": f"Bearer {access_token}",
|
||||||
|
"Notion-Version": "2022-06-28",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url=self._NOTION_PAGE_SEARCH, json=data, headers=headers)
|
||||||
|
response_json = response.json()
|
||||||
|
|
||||||
|
results.extend(response_json.get("results", []))
|
||||||
|
|
||||||
|
has_more = response_json.get("has_more", False)
|
||||||
|
next_cursor = response_json.get("next_cursor", None)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def notion_block_parent_page_id(self, access_token: str, block_id: str):
|
def notion_block_parent_page_id(self, access_token: str, block_id: str):
|
||||||
@ -260,13 +274,26 @@ class NotionOAuth(OAuthDataSource):
|
|||||||
return "workspace"
|
return "workspace"
|
||||||
|
|
||||||
def notion_database_search(self, access_token: str):
|
def notion_database_search(self, access_token: str):
|
||||||
data = {"filter": {"value": "database", "property": "object"}}
|
results = []
|
||||||
headers = {
|
next_cursor = None
|
||||||
"Content-Type": "application/json",
|
has_more = True
|
||||||
"Authorization": f"Bearer {access_token}",
|
|
||||||
"Notion-Version": "2022-06-28",
|
while has_more:
|
||||||
}
|
data = {
|
||||||
response = requests.post(url=self._NOTION_PAGE_SEARCH, json=data, headers=headers)
|
"filter": {"value": "database", "property": "object"},
|
||||||
response_json = response.json()
|
**({"start_cursor": next_cursor} if next_cursor else {}),
|
||||||
results = response_json.get("results", [])
|
}
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": f"Bearer {access_token}",
|
||||||
|
"Notion-Version": "2022-06-28",
|
||||||
|
}
|
||||||
|
response = requests.post(url=self._NOTION_PAGE_SEARCH, json=data, headers=headers)
|
||||||
|
response_json = response.json()
|
||||||
|
|
||||||
|
results.extend(response_json.get("results", []))
|
||||||
|
|
||||||
|
has_more = response_json.get("has_more", False)
|
||||||
|
next_cursor = response_json.get("next_cursor", None)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user