check if feature is granted when process youtube video

This commit is contained in:
Hongbo Wu
2024-03-28 14:41:30 +08:00
parent 45417efd0c
commit 1afec1ddf3
3 changed files with 25 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -132,13 +132,14 @@ export const findUserFeatures = async (userId: string): Promise<string[]> => {
).map((feature) => feature.name)
}
export const findFeatureByName = async (
export const findGrantedFeatureByName = async (
name: FeatureName,
userId: string
): Promise<Feature | null> => {
return await getRepository(Feature).findOneBy({
return getRepository(Feature).findOneBy({
name,
user: { id: userId },
grantedAt: Not(IsNull()),
})
}