diff --git a/packages/api/src/jobs/process-youtube-video.ts b/packages/api/src/jobs/process-youtube-video.ts index 2802e89a6..d8a067897 100644 --- a/packages/api/src/jobs/process-youtube-video.ts +++ b/packages/api/src/jobs/process-youtube-video.ts @@ -1,21 +1,19 @@ -import { logger } from '../utils/logger' +import { Storage } from '@google-cloud/storage' +import { PromptTemplate } from '@langchain/core/prompts' +import { OpenAI } from '@langchain/openai' +import { parseHTML } from 'linkedom' +import showdown from 'showdown' +import * as stream from 'stream' +import { Chapter, Client as YouTubeClient } from 'youtubei' +import { LibraryItem, LibraryItemState } from '../entity/library_item' +import { env } from '../env' import { authTrx } from '../repository' import { libraryItemRepository } from '../repository/library_item' -import { LibraryItem, LibraryItemState } from '../entity/library_item' - -import { Chapter, Client as YouTubeClient } from 'youtubei' -import showdown from 'showdown' -import { parseHTML } from 'linkedom' -import { parsePreparedContent } from '../utils/parser' -import { OpenAI } from '@langchain/openai' -import { PromptTemplate } from '@langchain/core/prompts' +import { FeatureName, findGrantedFeatureByName } from '../services/features' import { enqueueProcessYouTubeTranscript } from '../utils/createTask' -import { env } from '../env' -import * as stream from 'stream' - -import { Storage } from '@google-cloud/storage' import { stringToHash } from '../utils/helpers' -import { FeatureName, findFeatureByName } from '../services/features' +import { logger } from '../utils/logger' +import { parsePreparedContent } from '../utils/parser' export interface ProcessYouTubeVideoJobData { userId: string @@ -394,7 +392,10 @@ export const processYouTubeVideo = async ( } if ( - await findFeatureByName(FeatureName.YouTubeTranscripts, jobData.userId) + await findGrantedFeatureByName( + FeatureName.YouTubeTranscripts, + jobData.userId + ) ) { if ('getTranscript' in video && duration > 0 && duration < 1801) { // If the video has a transcript available, put a placehold in and diff --git a/packages/api/src/pubsub.ts b/packages/api/src/pubsub.ts index 237a5801f..2214d787b 100644 --- a/packages/api/src/pubsub.ts +++ b/packages/api/src/pubsub.ts @@ -3,7 +3,6 @@ import express from 'express' import { RuleEventType } from './entity/rule' import { env } from './env' import { ReportType } from './generated/graphql' -import { FeatureName, findFeatureByName } from './services/features' import { enqueueExportItem, enqueueProcessYouTubeVideo, @@ -87,12 +86,12 @@ export const createPubSubClient = (): PubsubClient => { }) if (type === EntityType.PAGE) { - if (await findFeatureByName(FeatureName.AISummaries, userId)) { - // await enqueueAISummarizeJob({ - // userId, - // libraryItemId, - // }) - } + // if (await findGrantedFeatureByName(FeatureName.AISummaries, userId)) { + // await enqueueAISummarizeJob({ + // userId, + // libraryItemId, + // }) + // } const isYoutubeVideo = (data: any): data is { originalUrl: string } => { return 'originalUrl' in data diff --git a/packages/api/src/services/features.ts b/packages/api/src/services/features.ts index e82a21bbc..cb5ca67b2 100644 --- a/packages/api/src/services/features.ts +++ b/packages/api/src/services/features.ts @@ -132,13 +132,14 @@ export const findUserFeatures = async (userId: string): Promise => { ).map((feature) => feature.name) } -export const findFeatureByName = async ( +export const findGrantedFeatureByName = async ( name: FeatureName, userId: string ): Promise => { - return await getRepository(Feature).findOneBy({ + return getRepository(Feature).findOneBy({ name, user: { id: userId }, + grantedAt: Not(IsNull()), }) }