feat(editor): ✨ Add file upload input
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import { Client } from 'minio'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
import { badRequest, methodNotAllowed } from 'utils'
|
||||
import { badRequest, generatePresignedUrl, methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = async (
|
||||
req: NextApiRequest,
|
||||
@ -21,27 +20,14 @@ const handler = async (
|
||||
!process.env.S3_ACCESS_KEY ||
|
||||
!process.env.S3_SECRET_KEY
|
||||
)
|
||||
return res.send({
|
||||
message:
|
||||
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY',
|
||||
})
|
||||
|
||||
const s3 = new Client({
|
||||
endPoint: process.env.S3_ENDPOINT,
|
||||
port: process.env.S3_PORT ? Number(process.env.S3_PORT) : undefined,
|
||||
useSSL:
|
||||
process.env.S3_SSL && process.env.S3_SSL === 'false' ? false : true,
|
||||
accessKey: process.env.S3_ACCESS_KEY,
|
||||
secretKey: process.env.S3_SECRET_KEY,
|
||||
region: process.env.S3_REGION,
|
||||
})
|
||||
|
||||
return badRequest(
|
||||
res,
|
||||
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
|
||||
)
|
||||
const filePath = req.query.filePath as string | undefined
|
||||
if (!filePath) return badRequest(res)
|
||||
const presignedUrl = await s3.presignedPutObject(
|
||||
process.env.S3_BUCKET ?? 'typebot',
|
||||
filePath
|
||||
)
|
||||
const fileType = req.query.fileType as string | undefined
|
||||
if (!filePath || !fileType) return badRequest(res)
|
||||
const presignedUrl = generatePresignedUrl({ fileType, filePath })
|
||||
|
||||
return res.status(200).send({ presignedUrl })
|
||||
}
|
||||
|
Reference in New Issue
Block a user