cosette/server/api/cosette.post.js

17 lines
543 B
JavaScript
Raw Normal View History

2022-08-11 09:57:51 +02:00
import { add } from '../controller'
2022-08-12 18:23:03 +02:00
import { useBody, callHandler, sendRedirect } from 'h3'
2022-08-11 09:57:51 +02:00
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)
2022-08-12 18:23:03 +02:00
body.imgs = [event.req.file?.filename]
2022-08-11 09:57:51 +02:00
add(body)
2022-08-13 11:56:59 +02:00
return sendRedirect(event, 'http://localhost:3000')
2022-08-11 09:57:51 +02:00
} catch (e) {
return { success: false, reason: e.message }
}
2022-08-13 11:56:59 +02:00
})