mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-12 20:17:16 +02:00
voice note and sticker pack and gifs
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { getSessionUser } from "@/lib/auth"
|
||||
import { writeFile } from "node:fs/promises"
|
||||
import { join } from "node:path"
|
||||
import crypto from "node:crypto"
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const user = await getSessionUser()
|
||||
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
||||
|
||||
const formData = await request.formData()
|
||||
const file = formData.get("audio") as File | null
|
||||
if (!file) return NextResponse.json({ error: "No audio file" }, { status: 400 })
|
||||
|
||||
const duration = parseFloat(formData.get("duration")?.toString() || "0")
|
||||
|
||||
const ext = file.name.endsWith(".webm") ? "webm" : "webm"
|
||||
const filename = `${crypto.randomUUID()}.${ext}`
|
||||
const buffer = Buffer.from(await file.arrayBuffer())
|
||||
const savePath = join(process.cwd(), "public", "uploads", "voice", filename)
|
||||
await writeFile(savePath, buffer)
|
||||
|
||||
return NextResponse.json({ url: `/uploads/voice/${filename}`, duration })
|
||||
} catch (error) {
|
||||
console.error("Voice upload error:", error)
|
||||
return NextResponse.json({ error: "Upload failed" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user