Finallyyyyyy finished the whole Speaking flow along with the solution page

This commit is contained in:
Tiago Ribeiro
2023-07-14 14:15:07 +01:00
parent 2c10a203a5
commit 121ac8ba4d
10 changed files with 206 additions and 76 deletions

View File

@@ -20,26 +20,25 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const storage = getStorage(app);
const form = formidable({keepExtensions: true, uploadDir: "./"});
form.parse(req, (err, fields, files) => {
const audioFile = (files.audio as unknown as PersistentFile[])[0];
const audioFileRef = ref(storage, `speaking_recordings/${(audioFile as any).newFilename}`);
const [fields, files] = await form.parse(req);
const audioFile = (files.audio as unknown as PersistentFile[])[0];
const audioFileRef = ref(storage, `speaking_recordings/${(audioFile as any).newFilename}`);
const binary = fs.readFileSync((audioFile as any).filepath).buffer;
uploadBytes(audioFileRef, binary).then(async (snapshot) => {
const backendRequest = await axios.post(
`${process.env.BACKEND_URL}/speaking_task_1`,
{question: (fields.question as string[]).join(""), answer: snapshot.metadata.fullPath},
{
headers: {
Authorization: `Bearer ${process.env.BACKEND_JWT}`,
},
},
);
const binary = fs.readFileSync((audioFile as any).filepath).buffer;
const snapshot = await uploadBytes(audioFileRef, binary);
fs.rmSync((audioFile as any).filepath);
res.status(200).json({...backendRequest.data, fullPath: snapshot.metadata.fullPath});
});
});
const backendRequest = await axios.post(
`${process.env.BACKEND_URL}/speaking_task_1`,
{question: (fields.question as string[]).join(""), answer: snapshot.metadata.fullPath},
{
headers: {
Authorization: `Bearer ${process.env.BACKEND_JWT}`,
},
},
);
fs.rmSync((audioFile as any).filepath);
res.status(200).json({...backendRequest.data, fullPath: snapshot.metadata.fullPath});
}
export const config = {