From 4af340f30e93fd0f26f3414b9eb086a4c13e40e8 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 29 Aug 2022 11:49:10 +0800 Subject: [PATCH] Add the priority to request param and use the correct queue accordingly --- packages/api/src/routers/article_router.ts | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/api/src/routers/article_router.ts b/packages/api/src/routers/article_router.ts index 68e804071..487b32c77 100644 --- a/packages/api/src/routers/article_router.ts +++ b/packages/api/src/routers/article_router.ts @@ -73,13 +73,18 @@ export function articleRouter() { }) router.get( - '/:id/:outputFormat/:voice?', + '/:id/:outputFormat/:priority/:voice?', cors(corsConfig), async (req, res) => { const articleId = req.params.id const outputFormat = req.params.outputFormat const voice = req.params.voice - if (!articleId || !['mp3', 'speech-marks'].includes(outputFormat)) { + const priority = req.params.priority + if ( + !articleId || + !['mp3', 'speech-marks'].includes(outputFormat) || + !['low', 'high'].includes(priority) + ) { return res.status(400).send('Invalid data') } const token = req.cookies?.auth || req.headers?.authorization @@ -153,14 +158,13 @@ export function articleRouter() { voice: voice || userPersonalization?.speechVoice || 'en-US-JennyNeural', }) // enqueue a task to convert text to speech - const taskName = await enqueueTextToSpeech( - uid, - speech.id, - page.content, - 'ssml', - speech.voice, - env.fileUpload.gcsUploadBucket - ) + const taskName = await enqueueTextToSpeech({ + userId: uid, + speechId: speech.id, + text: page.content, + voice: speech.voice, + priority: priority as 'low' | 'high', + }) logger.info('Start Text to speech task', { taskName }) res.status(202).send('Text to speech task started') }