Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
9e842330
Commit
9e842330
authored
Jun 15, 2023
by
jyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query block's parent page
parent
147ad5b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
oauth_data_source.py
api/libs/oauth_data_source.py
+16
-2
No files found.
api/libs/oauth_data_source.py
View file @
9e842330
...
@@ -25,6 +25,7 @@ class NotionOAuth(OAuthDataSource):
...
@@ -25,6 +25,7 @@ class NotionOAuth(OAuthDataSource):
_AUTH_URL
=
'https://api.notion.com/v1/oauth/authorize'
_AUTH_URL
=
'https://api.notion.com/v1/oauth/authorize'
_TOKEN_URL
=
'https://api.notion.com/v1/oauth/token'
_TOKEN_URL
=
'https://api.notion.com/v1/oauth/token'
_NOTION_PAGE_SEARCH
=
"https://api.notion.com/v1/search"
_NOTION_PAGE_SEARCH
=
"https://api.notion.com/v1/search"
_NOTION_BLOCK_SEARCH
=
"https://api.notion.com/v1/blocks"
def
get_authorization_url
(
self
):
def
get_authorization_url
(
self
):
params
=
{
params
=
{
...
@@ -145,7 +146,7 @@ class NotionOAuth(OAuthDataSource):
...
@@ -145,7 +146,7 @@ class NotionOAuth(OAuthDataSource):
parent
=
page_result
[
'parent'
]
parent
=
page_result
[
'parent'
]
parent_type
=
parent
[
'type'
]
parent_type
=
parent
[
'type'
]
if
parent_type
==
'block_id'
:
if
parent_type
==
'block_id'
:
continue
parent_id
=
self
.
notion_block_parent_page_id
(
access_token
,
parent
[
parent_type
])
elif
parent_type
==
'workspace'
:
elif
parent_type
==
'workspace'
:
parent_id
=
'root'
parent_id
=
'root'
else
:
else
:
...
@@ -184,7 +185,7 @@ class NotionOAuth(OAuthDataSource):
...
@@ -184,7 +185,7 @@ class NotionOAuth(OAuthDataSource):
parent
=
database_result
[
'parent'
]
parent
=
database_result
[
'parent'
]
parent_type
=
parent
[
'type'
]
parent_type
=
parent
[
'type'
]
if
parent_type
==
'block_id'
:
if
parent_type
==
'block_id'
:
continue
parent_id
=
self
.
notion_block_parent_page_id
(
access_token
,
parent
[
parent_type
])
elif
parent_type
==
'workspace'
:
elif
parent_type
==
'workspace'
:
parent_id
=
'root'
parent_id
=
'root'
else
:
else
:
...
@@ -216,6 +217,19 @@ class NotionOAuth(OAuthDataSource):
...
@@ -216,6 +217,19 @@ class NotionOAuth(OAuthDataSource):
results
=
response_json
[
'results'
]
results
=
response_json
[
'results'
]
return
results
return
results
def
notion_block_parent_page_id
(
self
,
access_token
:
str
,
block_id
:
str
):
headers
=
{
'Authorization'
:
f
"Bearer {access_token}"
,
'Notion-Version'
:
'2022-06-28'
,
}
response
=
requests
.
get
(
url
=
f
'{self._NOTION_PAGE_SEARCH}/{block_id}'
,
headers
=
headers
)
response_json
=
response
.
json
()
parent
=
response_json
[
'parent'
]
parent_type
=
parent
[
'type'
]
if
parent_type
==
'block_id'
:
return
self
.
notion_block_parent_page_id
(
access_token
,
parent
[
parent_type
])
return
parent
[
parent_type
]
def
notion_database_search
(
self
,
access_token
:
str
):
def
notion_database_search
(
self
,
access_token
:
str
):
data
=
{
data
=
{
'filter'
:
{
'filter'
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment