mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
create/add RSS labels to the library item when feedUrl is there
This commit is contained in:
parent
ad63c75e63
commit
36777568ac
6 changed files with 59 additions and 42 deletions
|
|
@ -61,9 +61,9 @@ import { createPageSaveRequest } from '../../services/create_page_save_request'
|
|||
import { findHighlightsByLibraryItemId } from '../../services/highlights'
|
||||
import {
|
||||
addLabelsToLibraryItem,
|
||||
createAndSaveLabelsInLibraryItem,
|
||||
findLabelsByIds,
|
||||
findOrCreateLabels,
|
||||
saveLabelsInLibraryItem,
|
||||
} from '../../services/labels'
|
||||
import {
|
||||
createLibraryItem,
|
||||
|
|
@ -355,11 +355,13 @@ export const createArticleResolver = authorized<
|
|||
)
|
||||
}
|
||||
|
||||
// save labels in item
|
||||
if (inputLabels) {
|
||||
const labels = await findOrCreateLabels(inputLabels, user.id)
|
||||
await saveLabelsInLibraryItem(labels, libraryItemToReturn.id, user.id)
|
||||
}
|
||||
await createAndSaveLabelsInLibraryItem(
|
||||
libraryItemToReturn.id,
|
||||
uid,
|
||||
inputLabels,
|
||||
rssFeedUrl,
|
||||
pubsub
|
||||
)
|
||||
|
||||
log.info(
|
||||
'item created in database',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
import express from 'express'
|
||||
import {
|
||||
findOrCreateLabels,
|
||||
saveLabelsInLibraryItem,
|
||||
} from '../../services/labels'
|
||||
import { createAndSaveLabelsInLibraryItem } from '../../services/labels'
|
||||
import { saveFeedItemInFollowing } from '../../services/library_item'
|
||||
import { logger } from '../../utils/logger'
|
||||
|
||||
|
|
@ -69,19 +66,12 @@ export function followingServiceRouter() {
|
|||
|
||||
logger.info('feed item saved in following')
|
||||
|
||||
// add RSS label to the item
|
||||
const labels = await findOrCreateLabels(
|
||||
[
|
||||
{
|
||||
name: 'RSS',
|
||||
},
|
||||
],
|
||||
userId
|
||||
)
|
||||
await saveLabelsInLibraryItem(
|
||||
labels,
|
||||
// save RSS label in the item
|
||||
await createAndSaveLabelsInLibraryItem(
|
||||
result.identifiers[0].id,
|
||||
userId,
|
||||
[{ name: 'RSS' }],
|
||||
undefined,
|
||||
undefined,
|
||||
true
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity
|
|||
import { EntityLabel } from '../entity/entity_label'
|
||||
import { Label } from '../entity/label'
|
||||
import { LibraryItem } from '../entity/library_item'
|
||||
import { createPubSubClient, EntityType } from '../pubsub'
|
||||
import { createPubSubClient, EntityType, PubsubClient } from '../pubsub'
|
||||
import { authTrx } from '../repository'
|
||||
import { CreateLabelInput, labelRepository } from '../repository/label'
|
||||
import { libraryItemRepository } from '../repository/library_item'
|
||||
|
|
@ -65,6 +65,33 @@ export const findOrCreateLabels = async (
|
|||
)
|
||||
}
|
||||
|
||||
export const createAndSaveLabelsInLibraryItem = async (
|
||||
libraryItemId: string,
|
||||
userId: string,
|
||||
labels?: CreateLabelInput[] | null,
|
||||
rssFeedUrl?: string | null,
|
||||
pubsub?: PubsubClient,
|
||||
skipPubSub?: boolean
|
||||
) => {
|
||||
if (rssFeedUrl) {
|
||||
// add rss label to labels
|
||||
labels = (labels || []).concat({ name: 'RSS' })
|
||||
}
|
||||
|
||||
// save labels in item
|
||||
if (labels && labels.length > 0) {
|
||||
const newLabels = await findOrCreateLabels(labels, userId)
|
||||
|
||||
await saveLabelsInLibraryItem(
|
||||
newLabels,
|
||||
libraryItemId,
|
||||
userId,
|
||||
pubsub,
|
||||
skipPubSub
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const saveLabelsInLibraryItem = async (
|
||||
labels: Label[],
|
||||
libraryItemId: string,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { LibraryItem, LibraryItemState } from '../entity/library_item'
|
||||
import { getInternalLabelWithColor } from '../repository/label'
|
||||
import { enqueueThumbnailTask } from '../utils/createTask'
|
||||
import {
|
||||
cleanUrl,
|
||||
|
|
@ -16,7 +15,7 @@ import {
|
|||
parsePreparedContent,
|
||||
parseUrlMetadata,
|
||||
} from '../utils/parser'
|
||||
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
|
||||
import { createAndSaveLabelsInLibraryItem } from './labels'
|
||||
import {
|
||||
createLibraryItem,
|
||||
findLibraryItemByUrl,
|
||||
|
|
@ -81,8 +80,6 @@ export const saveEmail = async (
|
|||
return updatedLibraryItem
|
||||
}
|
||||
|
||||
const newsletterLabel = getInternalLabelWithColor('newsletter')
|
||||
|
||||
// start a transaction to create the library item and update the received email
|
||||
const newLibraryItem = await createLibraryItem(
|
||||
{
|
||||
|
|
@ -123,11 +120,10 @@ export const saveEmail = async (
|
|||
})
|
||||
}
|
||||
|
||||
if (newsletterLabel) {
|
||||
// add newsletter label
|
||||
const labels = await findOrCreateLabels([newsletterLabel], input.userId)
|
||||
await saveLabelsInLibraryItem(labels, newLibraryItem.id, input.userId)
|
||||
}
|
||||
// save newsletter label in the item
|
||||
await createAndSaveLabelsInLibraryItem(newLibraryItem.id, input.userId, [
|
||||
{ name: 'Newsletter' },
|
||||
])
|
||||
|
||||
await updateReceivedEmail(input.receivedEmailId, 'article', input.userId)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { User } from '../entity/user'
|
|||
import { homePageURL } from '../env'
|
||||
import { SaveErrorCode, SaveFileInput, SaveResult } from '../generated/graphql'
|
||||
import { getStorageFileDetails } from '../utils/uploads'
|
||||
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
|
||||
import { createAndSaveLabelsInLibraryItem } from './labels'
|
||||
import { updateLibraryItem } from './library_item'
|
||||
import { findUploadFileById, setFileUploadComplete } from './upload_file'
|
||||
|
||||
|
|
@ -40,10 +40,11 @@ export const saveFile = async (
|
|||
}
|
||||
|
||||
// add labels to item
|
||||
if (input.labels) {
|
||||
const labels = await findOrCreateLabels(input.labels, user.id)
|
||||
await saveLabelsInLibraryItem(labels, input.clientRequestId, user.id)
|
||||
}
|
||||
await createAndSaveLabelsInLibraryItem(
|
||||
input.clientRequestId,
|
||||
user.id,
|
||||
input.labels
|
||||
)
|
||||
|
||||
return {
|
||||
clientRequestId: input.clientRequestId,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import { parsePreparedContent } from '../utils/parser'
|
|||
import { contentReaderForLibraryItem } from '../utils/uploads'
|
||||
import { createPageSaveRequest } from './create_page_save_request'
|
||||
import { createHighlight } from './highlights'
|
||||
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
|
||||
import { createAndSaveLabelsInLibraryItem } from './labels'
|
||||
import { createLibraryItem, updateLibraryItem } from './library_item'
|
||||
|
||||
// where we can use APIs to fetch their underlying content.
|
||||
|
|
@ -160,11 +160,12 @@ export const savePage = async (
|
|||
clientRequestId = newItem.id
|
||||
}
|
||||
|
||||
// save labels in item
|
||||
if (input.labels) {
|
||||
const labels = await findOrCreateLabels(input.labels, user.id)
|
||||
await saveLabelsInLibraryItem(labels, clientRequestId, user.id)
|
||||
}
|
||||
await createAndSaveLabelsInLibraryItem(
|
||||
clientRequestId,
|
||||
user.id,
|
||||
input.labels,
|
||||
input.rssFeedUrl
|
||||
)
|
||||
}
|
||||
|
||||
// we don't want to create thumbnail for imported pages
|
||||
|
|
|
|||
Loading…
Reference in a new issue