fix readwise syncing error

This commit is contained in:
Hongbo Wu 2024-03-22 15:55:45 +08:00
parent f35ac036eb
commit ff78a4b266
3 changed files with 37 additions and 34 deletions

View file

@ -129,13 +129,14 @@ const exportItem = async (obj: RuleActionObj) => {
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,
name: integration.name,
}
logger.info('exporting item...', logObject)
try {
const client = getIntegrationClient(
integration.name,
integration.token,
@ -168,8 +169,7 @@ const exportItem = async (obj: RuleActionObj) => {
})
} catch (error) {
logger.error('failed to export item', {
userId,
integrationId: integration.id,
...logObject,
error,
})
}

View file

@ -1,6 +1,7 @@
import axios from 'axios'
import { HighlightType } from '../../entity/highlight'
import { logger } from '../../utils/logger'
import { getHighlightUrl } from '../highlights'
import { getHighlightUrl, HighlightEvent } from '../highlights'
import { ItemEvent } from '../library_item'
import { IntegrationClient } from './integration'
@ -84,31 +85,33 @@ export class ReadwiseClient implements IntegrationClient {
}
private _itemToReadwiseHighlight = (item: ItemEvent): ReadwiseHighlight[] => {
const category = item.siteName === 'Twitter' ? 'tweets' : 'articles'
return item.highlights
?.map((highlight) => {
// filter out highlights that are not of type highlight or have no quote
if (highlight.highlightType !== 'HIGHLIGHT' || !highlight.quote) {
return undefined
}
const isHighlight = (
highlight: HighlightEvent
): highlight is HighlightEvent & { quote: string } =>
highlight.highlightType === HighlightType.Highlight && !!highlight.quote
return {
text: highlight.quote,
title: item.title,
author: item.author || undefined,
highlight_url: item.slug
? getHighlightUrl(item.slug, highlight.id)
: undefined,
highlighted_at: (highlight.createdAt as Date).toISOString(),
category,
image_url: item.thumbnail || undefined,
location_type: 'order',
note: highlight.annotation || undefined,
source_type: 'omnivore',
source_url: item.originalUrl,
}
})
.filter((highlight) => highlight !== undefined) as ReadwiseHighlight[]
const category = item.siteName === 'Twitter' ? 'tweets' : 'articles'
return item.highlights
? item.highlights
// filter out highlights that are not of type highlight or have no quote
.filter(isHighlight)
.map((highlight) => ({
text: highlight.quote,
title: item.title,
author: item.author || undefined,
highlight_url: item.slug
? getHighlightUrl(item.slug, highlight.id)
: undefined,
highlighted_at: (highlight.createdAt as Date).toISOString(),
category,
image_url: item.thumbnail || undefined,
location_type: 'order',
note: highlight.annotation || undefined,
source_type: 'omnivore',
source_url: item.originalUrl,
}))
: []
}
private _syncWithReadwise = async (

View file

@ -104,7 +104,7 @@ const CreateRuleModal = (props: CreateRuleModalProps): JSX.Element => {
const value = Object.values(RuleEventType)[index]
return (
<Select.Option key={key} value={value}>
{key}
{key === 'LABEL_CREATED' ? 'LABEL_ATTACHED' : key}
</Select.Option>
)
})}