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

@@ -4,19 +4,23 @@ import {withIronSessionApiRoute} from "iron-session/next";
import {sessionOptions} from "@/lib/session";
import {getDownloadURL, getStorage, ref} from "firebase/storage";
import {app} from "@/firebase";
import axios from "axios";
// export default withIronSessionApiRoute(handler, sessionOptions);
export default handler;
export default withIronSessionApiRoute(handler, sessionOptions);
async function handler(req: NextApiRequest, res: NextApiResponse) {
// if (!req.session.user) {
// res.status(401).json({ok: false});
// return;
// }
if (!req.session.user) {
res.status(401).json({ok: false});
return;
}
const storage = getStorage(app);
const {path} = req.body as {path: string};
const pathReference = ref(storage, path);
getDownloadURL(pathReference).then((url) => res.status(200).json({url}));
const url = await getDownloadURL(pathReference);
const response = await axios.get(url, {responseType: "arraybuffer"});
res.status(200).send(response.data);
}