mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add libraryItemIds to the payload
This commit is contained in:
parent
57cb897839
commit
aeda4f5d5d
3 changed files with 29 additions and 14 deletions
|
|
@ -10,7 +10,10 @@ import {
|
|||
SSMLOptions,
|
||||
} from '@omnivore/text-to-speech-handler'
|
||||
import axios from 'axios'
|
||||
import { searchLibraryItems } from '../../services/library_item'
|
||||
import {
|
||||
findLibraryItemsByIds,
|
||||
searchLibraryItems,
|
||||
} from '../../services/library_item'
|
||||
import { redisDataSource } from '../../redis_data_source'
|
||||
import { htmlToMarkdown } from '../../utils/parser'
|
||||
import yaml from 'yaml'
|
||||
|
|
@ -27,6 +30,7 @@ export interface CreateDigestJobData {
|
|||
voices?: string[]
|
||||
language?: string
|
||||
rate?: string
|
||||
libraryItemIds?: string[]
|
||||
}
|
||||
|
||||
export interface CreateDigestJobResponse {
|
||||
|
|
@ -125,7 +129,10 @@ const getPreferencesList = async (userId: string): Promise<LibraryItem[]> => {
|
|||
}
|
||||
|
||||
// Makes multiple DB queries and combines the results
|
||||
const getCandidatesList = async (userId: string): Promise<LibraryItem[]> => {
|
||||
const getCandidatesList = async (
|
||||
userId: string,
|
||||
libraryItemIds?: string[]
|
||||
): Promise<LibraryItem[]> => {
|
||||
// use the queries from the digest definitions to lookup preferences
|
||||
// There should be a list of multiple queries we use. For now we can
|
||||
// hardcode these queries:
|
||||
|
|
@ -133,6 +140,10 @@ const getCandidatesList = async (userId: string): Promise<LibraryItem[]> => {
|
|||
// count: 100
|
||||
// reason: "most recent 100 items saved over 500 words
|
||||
|
||||
if (libraryItemIds) {
|
||||
return findLibraryItemsByIds(libraryItemIds, userId)
|
||||
}
|
||||
|
||||
const candidates = await Promise.all(
|
||||
digestDefinition.candidateSelectors.map(async (selector) => {
|
||||
// use the selector to fetch items
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ interface CreateDigestRequest {
|
|||
language?: string
|
||||
rate?: string
|
||||
schedule?: CreateDigestJobSchedule
|
||||
libraryItemIds?: string[]
|
||||
}
|
||||
|
||||
export function digestRouter() {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import { redisDataSource } from '../redis_data_source'
|
|||
import {
|
||||
authTrx,
|
||||
getColumns,
|
||||
getColumnsDbName,
|
||||
getRepository,
|
||||
queryBuilderToRawSql,
|
||||
} from '../repository'
|
||||
|
|
@ -625,13 +626,11 @@ export const buildQuery = (
|
|||
userId: string
|
||||
) => {
|
||||
// select all columns except content
|
||||
const selects: Select[] = getColumns(libraryItemRepository)
|
||||
.map((column) => ({ column: `library_item.${column}` }))
|
||||
const selects: Select[] = getColumnsDbName(libraryItemRepository)
|
||||
.filter(
|
||||
(select) =>
|
||||
select.column !== 'library_item.readableContent' &&
|
||||
select.column !== 'library_item.originalContent'
|
||||
(select) => select !== 'readable_content' && select !== 'original_content'
|
||||
)
|
||||
.map((column) => ({ column: `library_item.${column}` }))
|
||||
|
||||
const parameters: ObjectLiteral[] = []
|
||||
const orders: Sort[] = []
|
||||
|
|
@ -652,10 +651,18 @@ export const buildQuery = (
|
|||
queryBuilder.where('library_item.user_id = :userId', { userId })
|
||||
|
||||
// add select
|
||||
selects.forEach((select) => {
|
||||
selects.forEach((select, index) => {
|
||||
if (index === 0) {
|
||||
queryBuilder.select(select.column, select.alias)
|
||||
}
|
||||
|
||||
queryBuilder.addSelect(select.column, select.alias)
|
||||
})
|
||||
|
||||
if (args.includeContent) {
|
||||
queryBuilder.addSelect('library_item.readable_content')
|
||||
}
|
||||
|
||||
if (!args.includePending) {
|
||||
queryBuilder.andWhere("library_item.state <> 'PROCESSING'")
|
||||
}
|
||||
|
|
@ -754,18 +761,14 @@ export const findRecentLibraryItems = async (
|
|||
}
|
||||
|
||||
export const findLibraryItemsByIds = async (ids: string[], userId: string) => {
|
||||
const selectColumns = getColumns(libraryItemRepository)
|
||||
.filter(
|
||||
(column) => column !== 'readableContent' && column !== 'originalContent'
|
||||
)
|
||||
const selectColumns = getColumnsDbName(libraryItemRepository)
|
||||
.filter((column) => column !== 'original_content')
|
||||
.map((column) => `library_item.${column}`)
|
||||
return authTrx(
|
||||
async (tx) =>
|
||||
tx
|
||||
.createQueryBuilder(LibraryItem, 'library_item')
|
||||
.select(selectColumns)
|
||||
.leftJoinAndSelect('library_item.labels', 'labels')
|
||||
.leftJoinAndSelect('library_item.highlights', 'highlights')
|
||||
.where('library_item.id IN (:...ids)', { ids })
|
||||
.getMany(),
|
||||
undefined,
|
||||
|
|
|
|||
Loading…
Reference in a new issue