Skip to content

Commit

Permalink
✨ feat(res-body-res): Add new feature to microsoft-speech.ts, handleM…
Browse files Browse the repository at this point in the history
…icrosoftSpeechRequest.ts, and useRecognition.ts

- 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.
  • Loading branch information
canisminor1990 committed Nov 12, 2023
1 parent bd46db7 commit e9822a8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/microsoft-speech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
5 changes: 3 additions & 2 deletions src/server/handleMicrosoftSpeechRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
};
1 change: 1 addition & 0 deletions src/useSpeechRecognition/useRecognition.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down

0 comments on commit e9822a8

Please sign in to comment.