Skip to content

Commit 3a4cda3

Browse files
committed
add searchNotionPersonal
1 parent 208f5a7 commit 3a4cda3

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"**/out": true,
3333
"**/.open-next": true
3434
},
35-
"editor.rulers": [100],
35+
"editor.rulers": [
36+
100
37+
],
3638
"typescript.tsdk": ".yarn/sdks/typescript/lib",
3739
"search.useIgnoreFiles": false,
3840
"explorer.excludeGitIgnore": false,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notion-x",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"description": "My customization of NotionX's react-notion-x. For personal use only!",
55
"main": "dist/index.js",
66
"module": "dist/index.esm.js",

src/lib/db.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,55 @@ export async function searchNotion(
486486
body: JSON.stringify(body)
487487
}).then(response => response.json())
488488
}
489+
490+
// When a database is publised, we open that page and use the search API to get the results
491+
// It doesn't use notion.so/api/v1/search, it uses personal.notion.site/api/v3/search instead
492+
// It doesn't require any token or active user!
493+
export async function searchNotionPersonal(
494+
params: SearchParams,
495+
apiUrl: string,
496+
dbId: string
497+
): Promise<any> {
498+
if (!apiUrl) throw new Error('apiUrl is not defined')
499+
500+
const headers: any = {
501+
'Content-Type': 'application/json'
502+
}
503+
504+
if (!dbId) {
505+
throw new Error('dbId is not defined')
506+
}
507+
508+
const body = {
509+
type: 'BlocksInAncestor',
510+
query: params.query,
511+
ancestorId: idToUuid(dbId),
512+
source: 'quick_find_input_change',
513+
sort: {
514+
field: 'relevance'
515+
},
516+
limit: params.limit || 100,
517+
filters: {
518+
isDeletedOnly: false,
519+
excludeTemplates: false,
520+
navigableBlockContentOnly: false,
521+
requireEditPermissions: false,
522+
includePublicPagesWithoutExplicitAccess: true,
523+
ancestors: [],
524+
createdBy: [],
525+
editedBy: [],
526+
lastEditedTime: {},
527+
createdTime: {},
528+
inTeams: [],
529+
...params.filters
530+
}
531+
}
532+
533+
const url = `${apiUrl}/search`
534+
535+
return fetch(url, {
536+
method: 'POST',
537+
headers: headers,
538+
body: JSON.stringify(body)
539+
}).then(response => response.json())
540+
}

0 commit comments

Comments
 (0)