deduplicate notion page by omnivore id
This commit is contained in:
@ -115,10 +115,10 @@ export const createPubSubClient = (): PubsubClient => {
|
||||
}
|
||||
|
||||
export enum EntityType {
|
||||
ITEM = 'page',
|
||||
HIGHLIGHT = 'highlight',
|
||||
LABEL = 'label',
|
||||
RSS_FEED = 'feed',
|
||||
ITEM = 'PAGE',
|
||||
HIGHLIGHT = 'HIGHLIGHT',
|
||||
LABEL = 'LABEL',
|
||||
RSS_FEED = 'FEED',
|
||||
}
|
||||
|
||||
export interface PubsubClient {
|
||||
|
||||
@ -69,6 +69,8 @@ export const createHighlight = async (
|
||||
{
|
||||
id: libraryItemId,
|
||||
slug: newHighlight.libraryItem.slug,
|
||||
originalUrl: newHighlight.libraryItem.originalUrl,
|
||||
thumbnail: newHighlight.libraryItem.thumbnail,
|
||||
highlights: [cleanData],
|
||||
},
|
||||
userId
|
||||
@ -121,6 +123,8 @@ export const mergeHighlights = async (
|
||||
{
|
||||
id: libraryItemId,
|
||||
slug: newHighlight.libraryItem.slug,
|
||||
originalUrl: newHighlight.libraryItem.originalUrl,
|
||||
thumbnail: newHighlight.libraryItem.thumbnail,
|
||||
highlights: [newHighlight],
|
||||
},
|
||||
userId
|
||||
@ -154,15 +158,15 @@ export const updateHighlight = async (
|
||||
})
|
||||
|
||||
const libraryItemId = updatedHighlight.libraryItem.id
|
||||
await pubsub.entityUpdated<ItemEvent>(
|
||||
EntityType.HIGHLIGHT,
|
||||
{
|
||||
id: libraryItemId,
|
||||
slug: updatedHighlight.libraryItem.slug,
|
||||
highlights: [highlight],
|
||||
} as ItemEvent,
|
||||
userId
|
||||
)
|
||||
// await pubsub.entityUpdated<ItemEvent>(
|
||||
// EntityType.HIGHLIGHT,
|
||||
// {
|
||||
// id: libraryItemId,
|
||||
// slug: updatedHighlight.libraryItem.slug,
|
||||
// highlights: [highlight],
|
||||
// } as ItemEvent,
|
||||
// userId
|
||||
// )
|
||||
|
||||
await enqueueUpdateHighlight({
|
||||
libraryItemId,
|
||||
|
||||
@ -63,10 +63,7 @@ interface NotionPage {
|
||||
'Original URL'?: {
|
||||
url: string
|
||||
}
|
||||
'Omnivore ID': {
|
||||
url: string
|
||||
}
|
||||
'Omnivore URL'?: {
|
||||
'Omnivore URL': {
|
||||
url: string
|
||||
}
|
||||
'Saved At'?: {
|
||||
@ -230,14 +227,9 @@ export class NotionClient implements IntegrationClient {
|
||||
url: item.originalUrl,
|
||||
}
|
||||
: undefined,
|
||||
'Omnivore ID': {
|
||||
url: item.id,
|
||||
'Omnivore URL': {
|
||||
url: `${env.client.url}/me/${item.id}`,
|
||||
},
|
||||
'Omnivore URL': item.slug
|
||||
? {
|
||||
url: `${env.client.url}/me/${item.slug}`,
|
||||
}
|
||||
: undefined,
|
||||
'Saved At': item.savedAt
|
||||
? {
|
||||
date: {
|
||||
@ -312,14 +304,14 @@ export class NotionClient implements IntegrationClient {
|
||||
await this.client.pages.create(page)
|
||||
}
|
||||
|
||||
private findPage = async (id: string, databaseId: string) => {
|
||||
private findPage = async (url: string, databaseId: string) => {
|
||||
const response = await this.client.databases.query({
|
||||
database_id: databaseId,
|
||||
page_size: 1,
|
||||
filter: {
|
||||
property: 'Omnivore ID',
|
||||
property: 'Omnivore URL',
|
||||
url: {
|
||||
equals: id,
|
||||
equals: url,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@ -101,16 +101,14 @@ export class ReadwiseClient implements IntegrationClient {
|
||||
text: highlight.quote,
|
||||
title: item.title,
|
||||
author: item.author || undefined,
|
||||
highlight_url: item.slug
|
||||
? getHighlightUrl(item.slug, highlight.id)
|
||||
: undefined,
|
||||
highlight_url: getHighlightUrl(item.slug as string, highlight.id),
|
||||
highlighted_at: highlight.createdAt as string | undefined,
|
||||
category,
|
||||
image_url: item.thumbnail || undefined,
|
||||
location_type: 'order',
|
||||
note: highlight.annotation || undefined,
|
||||
source_type: 'omnivore',
|
||||
source_url: item.originalUrl,
|
||||
source_url: item.originalUrl as string,
|
||||
}
|
||||
})
|
||||
: []
|
||||
|
||||
@ -13,8 +13,6 @@ import { CreateLabelInput, labelRepository } from '../repository/label'
|
||||
import { Merge } from '../util'
|
||||
import { bulkEnqueueUpdateLabels } from '../utils/createTask'
|
||||
import { deepDelete } from '../utils/helpers'
|
||||
import { logger } from '../utils/logger'
|
||||
import { findHighlightById } from './highlights'
|
||||
import { findLibraryItemIdsByLabelId, ItemEvent } from './library_item'
|
||||
|
||||
const columnToDelete = ['description', 'createdAt'] as const
|
||||
@ -213,30 +211,30 @@ export const saveLabelsInHighlight = async (
|
||||
)
|
||||
})
|
||||
|
||||
const highlight = await findHighlightById(highlightId, userId)
|
||||
if (!highlight) {
|
||||
logger.error('Highlight not found', { highlightId, userId })
|
||||
return
|
||||
}
|
||||
// const highlight = await findHighlightById(highlightId, userId)
|
||||
// if (!highlight) {
|
||||
// logger.error('Highlight not found', { highlightId, userId })
|
||||
// return
|
||||
// }
|
||||
|
||||
const libraryItemId = highlight.libraryItemId
|
||||
// create pubsub event
|
||||
await pubsub.entityCreated<ItemEvent>(
|
||||
EntityType.LABEL,
|
||||
{
|
||||
id: libraryItemId,
|
||||
highlights: [
|
||||
{
|
||||
id: highlightId,
|
||||
labels: labels.map((l) => deepDelete(l, columnToDelete)),
|
||||
},
|
||||
],
|
||||
},
|
||||
userId
|
||||
)
|
||||
// const libraryItemId = highlight.libraryItemId
|
||||
// // create pubsub event
|
||||
// await pubsub.entityCreated<ItemEvent>(
|
||||
// EntityType.LABEL,
|
||||
// {
|
||||
// id: libraryItemId,
|
||||
// highlights: [
|
||||
// {
|
||||
// id: highlightId,
|
||||
// labels: labels.map((l) => deepDelete(l, columnToDelete)),
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// userId
|
||||
// )
|
||||
|
||||
// update labels in library item
|
||||
await bulkEnqueueUpdateLabels([{ libraryItemId, userId }])
|
||||
// // update labels in library item
|
||||
// await bulkEnqueueUpdateLabels([{ libraryItemId, userId }])
|
||||
}
|
||||
|
||||
export const findLabelsByIds = async (
|
||||
|
||||
@ -895,7 +895,10 @@ export const updateLibraryItem = async (
|
||||
|
||||
await pubsub.entityUpdated<ItemEvent>(
|
||||
EntityType.ITEM,
|
||||
{ ...libraryItem, id } as ItemEvent,
|
||||
{
|
||||
...libraryItem,
|
||||
id,
|
||||
} as ItemEvent,
|
||||
userId
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user