1
0
Ответвление 0
cosette/server/api/cosette.post.js

16 строки
537 Б
JavaScript

import { add } from '../controller'
import { readBody, 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 readBody(event)
body.images = event.req.files.map(f => f.filename)
add(body)
return sendRedirect(event, '/')
} catch (e) {
return { success: false, reason: e.message }
}
})