cosette/server/api/cosette.post.js

17 lines
537 B
JavaScript
Raw Normal View History

2022-08-11 09:57:51 +02:00
import { add } from '../controller'
2022-08-23 23:26:57 +02:00
import { readBody, 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)
2022-08-23 23:26:57 +02:00
const body = await readBody(event)
body.images = event.req.files.map(f => f.filename)
2022-08-11 09:57:51 +02:00
add(body)
2022-08-18 09:44:51 +02:00
return sendRedirect(event, '/')
2022-08-11 09:57:51 +02:00
} catch (e) {
return { success: false, reason: e.message }
}
2022-08-13 11:56:59 +02:00
})