deduplicate notion page by omnivore id

This commit is contained in:
Hongbo Wu
2024-03-22 17:16:33 +08:00
parent 0428da3b71
commit d67aea6d8a
6 changed files with 51 additions and 56 deletions

View File

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

View File

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

View File

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

View File

@ -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,
}
})
: []

View File

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

View File

@ -895,7 +895,10 @@ export const updateLibraryItem = async (
await pubsub.entityUpdated<ItemEvent>(
EntityType.ITEM,
{ ...libraryItem, id } as ItemEvent,
{
...libraryItem,
id,
} as ItemEvent,
userId
)