cosette/server/api/cosette.post.js
2022-08-18 09:44:51 +02:00

16 lines
523 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, '/')
} catch (e) {
return { success: false, reason: e.message }
}
})