cosette/server/api/cosette.post.js
2022-08-13 11:56:59 +02:00

16 lines
543 B
JavaScript

import { add } from '../controller'
import { useBody, callHandler, sendRedirect } from 'h3'
import { uploadService } from '../services/upload-service'
export default defineEventHandler(async (event) => {
try {
const handler = uploadService().generateHandler()
await callHandler(handler, event.req, event.res)
const body = await useBody(event)
body.imgs = [event.req.file?.filename]
add(body)
return sendRedirect(event, 'http://localhost:3000')
} catch (e) {
return { success: false, reason: e.message }
}
})