2
0

Use minio for presigned urls and remove aws sdk

This commit is contained in:
Baptiste Arnaud
2023-08-30 09:08:05 +02:00
parent 5d402d9a38
commit 9a79bc38ee
16 changed files with 236 additions and 327 deletions

View File

@@ -52,7 +52,6 @@
"@upstash/ratelimit": "^0.4.3",
"@upstash/redis": "^1.22.0",
"@use-gesture/react": "^10.2.27",
"aws-sdk": "2.1415.0",
"browser-image-compression": "2.0.2",
"canvas-confetti": "1.6.0",
"codemirror": "6.0.1",

View File

@@ -1,7 +1,7 @@
import { useToast } from '@/hooks/useToast'
import { Button, ButtonProps, chakra } from '@chakra-ui/react'
import { ChangeEvent, useState } from 'react'
import { uploadFiles } from '@typebot.io/lib'
import { uploadFiles } from '@typebot.io/lib/uploadFiles'
import { compressFile } from '@/helpers/compressFile'
type UploadButtonProps = {

View File

@@ -90,11 +90,17 @@ export const TypebotProvider = ({
{ typebotId: typebotId as string },
{
enabled: isDefined(typebotId),
onError: (error) =>
onError: (error) => {
if (error.data?.httpStatus === 404) {
showToast({ status: 'info', description: "Couldn't find typebot" })
push('/typebots')
return
}
showToast({
title: 'Error while fetching typebot. Refresh the page.',
description: error.message,
}),
})
},
}
)
@@ -103,11 +109,13 @@ export const TypebotProvider = ({
{ typebotId: typebotId as string },
{
enabled: isDefined(typebotId),
onError: (error) =>
onError: (error) => {
if (error.data?.httpStatus === 404) return
showToast({
title: 'Error while fetching published typebot',
description: error.message,
}),
})
},
}
)
@@ -134,12 +142,7 @@ export const TypebotProvider = ({
useEffect(() => {
if (!typebot && isDefined(localTypebot)) setLocalTypebot(undefined)
if (isFetchingTypebot) return
if (!typebot) {
showToast({ status: 'info', description: "Couldn't find typebot" })
push('/typebots')
return
}
if (isFetchingTypebot || !typebot) return
if (
typebot.id !== localTypebot?.id ||
new Date(typebot.updatedAt).getTime() >

View File

@@ -25,7 +25,7 @@ const handler = async (
const filePath = req.query.filePath as string | undefined
const fileType = req.query.fileType as string | undefined
if (!filePath || !fileType) return badRequest(res)
const presignedUrl = generatePresignedUrl({ fileType, filePath })
const presignedUrl = await generatePresignedUrl({ fileType, filePath })
return res.status(200).send({ presignedUrl })
}

View File

@@ -6232,17 +6232,7 @@
"type": "object",
"properties": {
"presignedUrl": {
"type": "object",
"properties": {
"url": {
"type": "string"
},
"fields": {}
},
"required": [
"url"
],
"additionalProperties": false
"type": "string"
},
"hasReachedStorageLimit": {
"type": "boolean"

View File

@@ -49,6 +49,6 @@
"dotenv-cli": "^7.2.1",
"tsx": "3.12.5",
"typescript": "4.9.5",
"webpack": "5.76.1"
"url": "^0.11.1"
}
}

View File

@@ -18,7 +18,6 @@
"@typebot.io/prisma": "workspace:*",
"ai": "2.1.32",
"@udecode/plate-common": "^21.1.5",
"aws-sdk": "2.1415.0",
"bot-engine": "workspace:*",
"chrono-node": "^2.6.4",
"cors": "2.8.5",

View File

@@ -32,10 +32,7 @@ export const getUploadUrl = publicProcedure
)
.output(
z.object({
presignedUrl: z.object({
url: z.string(),
fields: z.any(),
}),
presignedUrl: z.string(),
hasReachedStorageLimit: z.boolean(),
})
)
@@ -63,14 +60,9 @@ export const getUploadUrl = publicProcedure
message: 'File upload block not found',
})
const sizeLimit = fileUploadBlock.options.sizeLimit
? Math.min(fileUploadBlock.options.sizeLimit, 500)
: 10
const presignedUrl = generatePresignedUrl({
const presignedUrl = await generatePresignedUrl({
fileType,
filePath,
sizeLimit: sizeLimit * 1024 * 1024,
})
return {