Files
yt2mp3/server/routes/convert.post.ts
2026-01-16 13:45:15 +00:00

38 lines
1.0 KiB
TypeScript

export default defineEventHandler(async (event) => {
// this one requires auth
const config = await useRuntimeConfig(event)
const body = await readBody(event)
const session = await getUserSession(event)
//console.log(session)
const userId = session.secure?.user_id;
if (userId == undefined || userId == null)
throw createError({ status: 401 })
else if (body.song == undefined)
throw createError({ status: 400, message: "Song name required"})
const req = await fetch(config.fastapi_url + "/convert", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
video_url : body.url,
user_id : userId,
artist : body.artist || null,
album : body.album || null,
song : body.song
})
})
setResponseStatus(event, req.status)
setResponseHeader(event, "Content-Type", "application/json")
//console.log(await req.json())
return await req.json()
})