Finallyyyyyy finished the whole Speaking flow along with the solution page
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user