From e9822a84d1092720313e49f1168e9e93c6211ddd Mon Sep 17 00:00:00 2001 From: canisminor1990 Date: Sun, 12 Nov 2023 17:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(res-body-res):=20Add=20new=20f?= =?UTF-8?q?eature=20to=20microsoft-speech.ts,=20handleMicrosoftSpeechReque?= =?UTF-8?q?st.ts,=20and=20useRecognition.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - In microsoft-speech.ts, modify code to call "cors" function with additional argument "new Response(res.body, res)" - In handleMicrosoftSpeechRequest.ts, modify code to accept additional argument "options" and spread it into request configuration object - In useRecognition.ts, add comment to ignore TypeScript error This commit adds new features to multiple files to enhance functionality and address TypeScript error. --- api/microsoft-speech.ts | 2 +- src/server/handleMicrosoftSpeechRequest.ts | 5 +++-- src/useSpeechRecognition/useRecognition.ts | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/microsoft-speech.ts b/api/microsoft-speech.ts index f8e4818..9b62c17 100644 --- a/api/microsoft-speech.ts +++ b/api/microsoft-speech.ts @@ -11,5 +11,5 @@ export default async (req: Request) => { const origin = getAllowOrigins(req); if (!origin) return new Response('Origin Not Allowed', { status: 403 }); const res = await handleMicrosoftSpeechRequest(req); - return cors(req, res, { methods: ['POST'], origin }); + return cors(req, new Response(res.body, res), { methods: ['POST'], origin }); }; diff --git a/src/server/handleMicrosoftSpeechRequest.ts b/src/server/handleMicrosoftSpeechRequest.ts index 9bef80f..1032970 100644 --- a/src/server/handleMicrosoftSpeechRequest.ts +++ b/src/server/handleMicrosoftSpeechRequest.ts @@ -2,7 +2,7 @@ import { v4 as uuidv4 } from 'uuid'; import { MICROSOFT_SPPECH_URL } from '../const/api'; -export const handleMicrosoftSpeechRequest = async (req: Request) => { +export const handleMicrosoftSpeechRequest = async (req: Request, options?: any) => { const DEFAULT_HEADERS = new Headers({ 'accept': '*/*', 'accept-language': 'zh-CN,zh;q=0.9', @@ -26,7 +26,8 @@ export const handleMicrosoftSpeechRequest = async (req: Request) => { method: 'POST', // @ts-ignore responseType: 'arraybuffer', + ...options, }); - return new Response(res.body, res); + return res; }; diff --git a/src/useSpeechRecognition/useRecognition.ts b/src/useSpeechRecognition/useRecognition.ts index bc99204..5fa26dc 100644 --- a/src/useSpeechRecognition/useRecognition.ts +++ b/src/useSpeechRecognition/useRecognition.ts @@ -1,6 +1,7 @@ import { useCallback, useEffect, useState } from 'react'; const SpeechRecognition = + // @ts-ignore (globalThis as any)?.SpeechRecognition || (window as any)?.webkitSpeechRecognition; export const useRecognition = (