mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
commit
eae715820d
2 changed files with 16 additions and 5 deletions
|
|
@ -181,7 +181,10 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
|
|||
const ssml = `${startSsml(ssmlOptions)}${utteranceInput.text}${endSsml()}`
|
||||
// hash ssml to get the cache key
|
||||
const cacheKey = crypto.createHash('md5').update(ssml).digest('hex')
|
||||
const redisClient = await createRedisClient()
|
||||
const redisClient = await createRedisClient(
|
||||
process.env.REDIS_URL,
|
||||
process.env.REDIS_CERT
|
||||
)
|
||||
// find audio data in cache
|
||||
const cacheResult = await redisClient.get(cacheKey)
|
||||
if (cacheResult) {
|
||||
|
|
@ -207,12 +210,12 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
|
|||
return res.status(500).send({ errorCode: 'SYNTHESIZER_ERROR' })
|
||||
}
|
||||
const audioDataString = audioData.toString('hex')
|
||||
// save audio data to cache for 1 hour
|
||||
// save audio data to cache for 24 hours for mainly the newsletters
|
||||
await redisClient.set(
|
||||
cacheKey,
|
||||
JSON.stringify({ audioDataString, speechMarks }),
|
||||
{
|
||||
EX: 3600, // in seconds
|
||||
EX: 3600 * 24, // in seconds
|
||||
NX: true,
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
import { createClient } from 'redis'
|
||||
|
||||
export const createRedisClient = async () => {
|
||||
const redisClient = createClient({ url: process.env.REDIS_URL })
|
||||
export const createRedisClient = async (url?: string, cert?: string) => {
|
||||
const redisClient = createClient({
|
||||
url,
|
||||
socket: {
|
||||
tls: url?.startsWith('rediss://'), // rediss:// is the protocol for TLS
|
||||
cert: cert?.replace(/\\n/g, '\n'), // replace \n with new line
|
||||
rejectUnauthorized: false, // for self-signed certs
|
||||
},
|
||||
})
|
||||
|
||||
redisClient.on('error', (err) => console.error('Redis Client Error', err))
|
||||
|
||||
await redisClient.connect()
|
||||
console.log('Redis Client Connected:', url)
|
||||
|
||||
return redisClient
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue