2
0

feat(bubbles): Add image bubble

This commit is contained in:
Baptiste Arnaud
2022-01-20 16:14:47 +01:00
parent c43fd1d386
commit 2d178978ef
33 changed files with 848 additions and 142 deletions

View File

@ -8,39 +8,35 @@ const handler = async (
req: NextApiRequest,
res: NextApiResponse
): Promise<void> => {
try {
res.setHeader('Access-Control-Allow-Origin', '*')
if (req.method === 'GET') {
const session = await getSession({ req })
if (!session) {
res.status(401)
return
}
aws.config.update({
accessKeyId: process.env.S3_UPLOAD_KEY,
secretAccessKey: process.env.S3_UPLOAD_SECRET,
region: process.env.S3_UPLOAD_REGION,
signatureVersion: 'v4',
})
const s3 = new aws.S3()
const post = s3.createPresignedPost({
Bucket: process.env.S3_UPLOAD_BUCKET,
Fields: {
ACL: 'public-read',
key: req.query.key,
'Content-Type': req.query.fileType,
},
Expires: 120, // seconds
Conditions: [['content-length-range', 0, maxUploadFileSize]],
})
return res.status(200).json(post)
res.setHeader('Access-Control-Allow-Origin', '*')
if (req.method === 'GET') {
const session = await getSession({ req })
if (!session) {
res.status(401)
return
}
return methodNotAllowed(res)
} catch (err) {
console.log(err)
aws.config.update({
accessKeyId: process.env.S3_UPLOAD_KEY,
secretAccessKey: process.env.S3_UPLOAD_SECRET,
region: process.env.S3_UPLOAD_REGION,
signatureVersion: 'v4',
})
const s3 = new aws.S3()
const post = s3.createPresignedPost({
Bucket: process.env.S3_UPLOAD_BUCKET,
Fields: {
ACL: 'public-read',
key: req.query.key,
'Content-Type': req.query.fileType,
},
Expires: 120, // seconds
Conditions: [['content-length-range', 0, maxUploadFileSize]],
})
return res.status(200).json(post)
}
return methodNotAllowed(res)
}
export default handler