merge labels and highlights when saving a duplicate item

This commit is contained in:
Hongbo Wu
2024-01-16 17:46:41 +08:00
parent 242e6e0fa3
commit 38ee6c1331
2 changed files with 32 additions and 2 deletions

View File

@ -58,6 +58,34 @@ export const findOrCreateLabels = async (
)
}
export const createAndAddLabelsToLibraryItem = async (
libraryItemId: string,
userId: string,
labels?: CreateLabelInput[] | null,
rssFeedUrl?: string | null,
source?: LabelSource,
pubsub?: PubsubClient
) => {
if (rssFeedUrl) {
// add rss label to labels
labels = (labels || []).concat({ name: 'RSS' })
source = 'system'
}
// save labels in item
if (labels && labels.length > 0) {
const newLabels = await findOrCreateLabels(labels, userId)
await addLabelsToLibraryItem(
newLabels,
libraryItemId,
userId,
source,
pubsub
)
}
}
export const createAndSaveLabelsInLibraryItem = async (
libraryItemId: string,
userId: string,

View File

@ -24,7 +24,7 @@ import { parsePreparedContent } from '../utils/parser'
import { contentReaderForLibraryItem } from '../utils/uploads'
import { createPageSaveRequest } from './create_page_save_request'
import { createHighlight } from './highlights'
import { createAndSaveLabelsInLibraryItem } from './labels'
import { createAndAddLabelsToLibraryItem } from './labels'
import { createOrUpdateLibraryItem } from './library_item'
// where we can use APIs to fetch their underlying content.
@ -132,7 +132,8 @@ export const savePage = async (
)
clientRequestId = newItem.id
await createAndSaveLabelsInLibraryItem(
// merge labels
await createAndAddLabelsToLibraryItem(
clientRequestId,
user.id,
input.labels,
@ -157,6 +158,7 @@ export const savePage = async (
libraryItem: { id: clientRequestId },
}
// merge highlights
try {
await createHighlight(highlight, clientRequestId, user.id)
} catch (error) {