mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add function to test if a page should be transcribed
This commit is contained in:
parent
5622154e6c
commit
9b0093e3d2
2 changed files with 38 additions and 0 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import { getRepository } from '../entity/utils'
|
||||
import { Speech, SpeechState } from '../entity/speech'
|
||||
import { searchPages } from '../elastic/pages'
|
||||
import { Page } from '../elastic/types'
|
||||
import { SortBy, SortOrder } from '../utils/search'
|
||||
|
||||
export const setSpeechFailure = async (id: string) => {
|
||||
// update state
|
||||
|
|
@ -7,3 +10,37 @@ export const setSpeechFailure = async (id: string) => {
|
|||
state: SpeechState.FAILED,
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
* We should not transcribe the page when:
|
||||
** 1. User has no recent listens the last 30 days
|
||||
** 2. User has a recent listen but the page was saved after the listen
|
||||
*/
|
||||
export const shouldTranscribe = async (
|
||||
userId: string,
|
||||
page: Page
|
||||
): Promise<boolean> => {
|
||||
const [recentListenedPage, count] = (await searchPages(
|
||||
{
|
||||
dateFilters: [
|
||||
{
|
||||
field: 'listenedAt',
|
||||
startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
|
||||
},
|
||||
],
|
||||
sort: {
|
||||
by: SortBy.LISTENED,
|
||||
order: SortOrder.DESCENDING,
|
||||
},
|
||||
size: 1,
|
||||
},
|
||||
userId
|
||||
)) || [[], 0]
|
||||
if (count === 0) {
|
||||
return false
|
||||
}
|
||||
return (
|
||||
!!recentListenedPage[0].listenedAt &&
|
||||
page.savedAt < recentListenedPage[0].listenedAt
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export enum SortBy {
|
|||
SCORE = '_score',
|
||||
PUBLISHED = 'publishedAt',
|
||||
READ = 'readAt',
|
||||
LISTENED = 'listenedAt',
|
||||
}
|
||||
|
||||
export enum SortOrder {
|
||||
|
|
|
|||
Loading…
Reference in a new issue