Finalized the Speaking module exercise
This commit is contained in:
22
src/pages/api/speaking.ts
Normal file
22
src/pages/api/speaking.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
import type {NextApiRequest, NextApiResponse} from "next";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {getDownloadURL, getStorage, ref} from "firebase/storage";
|
||||
import {app} from "@/firebase";
|
||||
|
||||
// export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
export default handler;
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
// 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}));
|
||||
}
|
||||
Reference in New Issue
Block a user