Skip to content

Commit

Permalink
fix: do not request blocks for unsupported types (#1214)
Browse files Browse the repository at this point in the history
Fixes: #1213
  • Loading branch information
aalemayhu authored Jul 13, 2023
1 parent 3780500 commit 45b3e84
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controllers/NotionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class NotionController {
createdAt: '',
lastEditedAt: '',
id,
type: 'page',
});
res.json(blocks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('BlockHandler', () => {
lastEditedAt: '',
id: '07a7b319183642b9afecdcc4c456f73d',
all: true,
type: 'page',
});
const topLevelToggles = getToggleBlocks(blocks.results);
expect(topLevelToggles.length).toEqual(14);
Expand Down
3 changes: 3 additions & 0 deletions src/services/NotionService/BlockHandler/BlockHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class BlockHandler {
lastEditedAt: block.last_edited_time,
id: block.id,
all: this.useAll,
type: block.type,
});
const requestChildren = response2.results;
return await renderBack(this, requestChildren, response2, handleChildren);
Expand Down Expand Up @@ -274,6 +275,7 @@ class BlockHandler {
lastEditedAt: (page as PageObjectResponse).last_edited_time,
id: topLevelId,
all: rules.UNLIMITED,
type: 'page',
});
const blocks = response.results;
const flashCardTypes = rules.flaschardTypeNames();
Expand Down Expand Up @@ -320,6 +322,7 @@ class BlockHandler {
lastEditedAt: sd.last_edited_time,
id: sd.id,
all: rules.UNLIMITED,
type: sd.type,
});
const cBlocks = res.results.filter((b: GetBlockResponse) =>
flashCardTypes.includes((b as BlockObjectResponse).type)
Expand Down
17 changes: 17 additions & 0 deletions src/services/NotionService/NotionAPIWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import { getHeadingText } from './helpers/getHeadingText';
import getObjectTitle from './helpers/getObjectTitle';
import { getBlockCache } from './helpers/getBlockCache';
import { getDatabase } from '../../data_layer';
import { ValidNotionType } from './types';

const DEFAULT_PAGE_SIZE_LIMIT = 100 * 2;

export interface GetBlockParams {
createdAt: string;
lastEditedAt: string;
id: string;
type: ValidNotionType;
all?: boolean;
}

Expand All @@ -50,8 +52,22 @@ class NotionAPIWrapper {
lastEditedAt,
id,
all,
type,
}: GetBlockParams): Promise<ListBlockChildrenResponse> {
console.time(`getBlocks:${id}${all}`);

// Skip unsupported types to prevent validation errors
if (type === 'unsupported') {
return {
type: 'block',
block: {},
object: 'list',
next_cursor: null,
has_more: false,
results: [],
};
}

const cachedPayload = all
? await getBlockCache({
database: getDatabase(),
Expand Down Expand Up @@ -210,6 +226,7 @@ class NotionAPIWrapper {
lastEditedAt: '',
id: pageId,
all: rules.UNLIMITED,
type: 'page',
});
const globalTags = [];
if (useHeadings) {
Expand Down
1 change: 1 addition & 0 deletions src/services/NotionService/_mock/MockNotionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class MockNotionAPI extends NotionAPIWrapper {
lastEditedAt: '',
id,
all,
type: 'page',
});
savePayload(dataMockPath('ListBlockChildrenResponse', id), blocks);
return blocks;
Expand Down
1 change: 1 addition & 0 deletions src/services/NotionService/helpers/getColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default async function getColumn(
createdAt: '',
lastEditedAt: '',
id: parentId,
type: 'column_list',
});
const blocks = getBlocks?.results;
if (blocks?.length > 0 && blocks?.length >= index + 1) {
Expand Down

0 comments on commit 45b3e84

Please sign in to comment.