diff --git a/packages/api/src/jobs/integration/export_item.ts b/packages/api/src/jobs/integration/export_item.ts index a2a0f1456..a1b8f7cc2 100644 --- a/packages/api/src/jobs/integration/export_item.ts +++ b/packages/api/src/jobs/integration/export_item.ts @@ -35,41 +35,50 @@ export const exportItem = async (jobData: ExportItemJobData) => { return } - // currently only readwise integration is supported - const integration = integrations[0] + await Promise.all( + integrations.map(async (integration) => { + try { + const logObject = { + userId, + integrationId: integration.id, + } + logger.info('exporting item...', logObject) - const logObject = { - userId, - integrationId: integration.id, - } - logger.info('exporting item...', logObject) + const client = getIntegrationClient(integration.name, integration.token) - const client = getIntegrationClient(integration.name, integration.token) + const synced = await client.export(libraryItems) + if (!synced) { + logger.error('failed to export item', logObject) + return false + } - const synced = await client.export(libraryItems) - if (!synced) { - logger.error('failed to export item', logObject) - return false - } + const syncedAt = new Date() + logger.info('updating integration...', { + ...logObject, + syncedAt, + }) - const syncedAt = new Date() - logger.info('updating integration...', { - ...logObject, - syncedAt, - }) - - // update integration syncedAt if successful - const updated = await updateIntegration( - integration.id, - { - syncedAt, - }, - userId + // update integration syncedAt if successful + const updated = await updateIntegration( + integration.id, + { + syncedAt, + }, + userId + ) + logger.info('integration updated', { + ...logObject, + updated, + }) + } catch (error) { + logger.error('failed to export item', { + userId, + integrationId: integration.id, + error, + }) + } + }) ) - logger.info('integration updated', { - ...logObject, - updated, - }) return true } diff --git a/packages/api/src/services/integrations/notion.ts b/packages/api/src/services/integrations/notion.ts index 539c1a3ef..868a5ec57 100644 --- a/packages/api/src/services/integrations/notion.ts +++ b/packages/api/src/services/integrations/notion.ts @@ -35,6 +35,8 @@ export class NotionClient implements IntegrationClient { baseURL: 'https://api.notion.com/v1', timeout: this._timeout, }) + _parentPageId = process.env.NOTION_PAGE_ID + _token: string _client: Client @@ -83,9 +85,13 @@ export class NotionClient implements IntegrationClient { } private _itemToNotionPage = (item: LibraryItem): NotionPage => { + if (!this._parentPageId) { + throw new Error('Notion parent page ID is not set') + } + return { parent: { - page_id: '83a3f627ab9e44ac83fe657141aec615', + page_id: this._parentPageId, }, cover: item.thumbnail ? { @@ -111,9 +117,6 @@ export class NotionClient implements IntegrationClient { } export = async (items: LibraryItem[]): Promise => { - // find/create a parent page for all the items - const parentPageName = 'Omnivore' - const pages = items.map(this._itemToNotionPage) await Promise.all(pages.map((page) => this._createPage(page))) diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index 4a16c7c18..784b79c8e 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -989,7 +989,7 @@ export const createOrUpdateLibraryItem = async ( ) } - if (skipPubSub) { + if (skipPubSub || libraryItem.state === LibraryItemState.Processing) { return newLibraryItem }