Pre-fetch realistic voice only if user is opted in

This commit is contained in:
Hongbo Wu
2022-11-10 18:48:00 +08:00
parent f3e5076a29
commit b0938ee96c
5 changed files with 49 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import { google } from '@google-cloud/tasks/build/protos/protos'
import { IntegrationType } from '../entity/integration'
import { promisify } from 'util'
import * as jwt from 'jsonwebtoken'
import { signFeatureToken } from '../services/features'
import View = google.cloud.tasks.v2.Task.View
const logger = buildLogger('app.dispatch')
@ -347,6 +348,8 @@ export const enqueueTextToSpeech = async ({
isUltraRealisticVoice = false,
language,
rate,
featureName,
grantedAt,
}: {
userId: string
speechId: string
@ -360,6 +363,8 @@ export const enqueueTextToSpeech = async ({
isUltraRealisticVoice?: boolean
language?: string
rate?: string
featureName?: string
grantedAt?: Date | null
}): Promise<string> => {
const { GOOGLE_CLOUD_PROJECT } = process.env
const payload = {
@ -372,11 +377,7 @@ export const enqueueTextToSpeech = async ({
language,
rate,
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const token = await signToken({ uid: userId }, env.server.jwtSecret, {
expiresIn: '1h',
})
const token = signFeatureToken({ name: featureName, grantedAt }, userId)
const taskHandlerUrl = `${env.queue.textToSpeechTaskHandlerUrl}?token=${token}`
// If there is no Google Cloud Project Id exposed, it means that we are in local environment
if (env.dev.isLocal || !GOOGLE_CLOUD_PROJECT) {