diff --git a/packages/api/src/elastic/pages.ts b/packages/api/src/elastic/pages.ts index b8c6230f3..97b00cdf0 100644 --- a/packages/api/src/elastic/pages.ts +++ b/packages/api/src/elastic/pages.ts @@ -194,9 +194,10 @@ export const createPage = async ( refresh: ctx.refresh, }) + page.id = body._id as string await ctx.pubsub.entityCreated(EntityType.PAGE, page, ctx.uid) - return body._id as string + return page.id } catch (e) { console.error('failed to create a page in elastic', JSON.stringify(e)) return undefined @@ -317,6 +318,8 @@ export const getPageByParam = async ( export const getPageById = async (id: string): Promise => { try { + if (!id) return undefined + const { body } = await client.get({ index: INDEX_ALIAS, id, diff --git a/packages/api/src/elastic/types.ts b/packages/api/src/elastic/types.ts index 2e547afc0..f25c33ae4 100644 --- a/packages/api/src/elastic/types.ts +++ b/packages/api/src/elastic/types.ts @@ -247,15 +247,7 @@ export interface SearchItem { highlights?: Highlight[] } -const keys = [ - '_id', - 'url', - 'slug', - 'userId', - 'uploadFileId', - 'state', - 'id', -] as const +const keys = ['_id', 'url', 'slug', 'userId', 'uploadFileId', 'state'] as const export type ParamSet = PickTuple diff --git a/packages/api/src/routers/svc/text_to_speech.ts b/packages/api/src/routers/svc/text_to_speech.ts index 4994d64d5..f80f138ba 100644 --- a/packages/api/src/routers/svc/text_to_speech.ts +++ b/packages/api/src/routers/svc/text_to_speech.ts @@ -39,8 +39,8 @@ export function speechServiceRouter() { const data: { userId: string; type: string; id: string } = JSON.parse(msgStr) const { userId, type, id } = data - if (!userId || !type) { - logger.info('No userId or type found in message') + if (!userId || !type || !id) { + logger.info('Invalid data') return res.status(400).send('Bad Request') } @@ -49,13 +49,13 @@ export function speechServiceRouter() { return res.status(200).send('Not a page') } - // checks if this page needs to be synthesized automatically const page = await getPageById(id) if (!page) { logger.info('No page found', { id }) return res.status(200).send('No page found') } + // checks if this page needs to be synthesized automatically if (await shouldSynthesize(userId, page)) { logger.info('page needs to be synthesized') // initialize state