send created event only

This commit is contained in:
Hongbo Wu
2024-03-05 15:39:09 +08:00
parent 741f3213d9
commit f1b1f2c4c1
3 changed files with 47 additions and 35 deletions

View File

@ -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
}

View File

@ -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<boolean> => {
// 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)))

View File

@ -989,7 +989,7 @@ export const createOrUpdateLibraryItem = async (
)
}
if (skipPubSub) {
if (skipPubSub || libraryItem.state === LibraryItemState.Processing) {
return newLibraryItem
}