Skip to content

Commit

Permalink
🚑 (upload) Fix upload in embed
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Sep 21, 2023
1 parent 9d80a3f commit 85272af
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@typebot.io/schemas'
import { byId, isDefined } from '@typebot.io/lib'
import { z } from 'zod'
import { generatePresignedPostPolicy } from '@typebot.io/lib/s3/generatePresignedPostPolicy'
import { generatePresignedUrl } from '@typebot.io/lib/s3/deprecated/generatePresignedUrl'
import { env } from '@typebot.io/env'
import prisma from '@typebot.io/lib/prisma'

Expand All @@ -34,7 +34,6 @@ export const getUploadUrl = publicProcedure
.output(
z.object({
presignedUrl: z.string(),
formData: z.record(z.string(), z.any()),
hasReachedStorageLimit: z.boolean(),
})
)
Expand Down Expand Up @@ -62,15 +61,13 @@ export const getUploadUrl = publicProcedure
message: 'File upload block not found',
})

const presignedPostPolicy = await generatePresignedPostPolicy({
const presignedUrl = await generatePresignedUrl({
fileType,
filePath,
maxFileSize: env.NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE,
})

return {
presignedUrl: `${presignedPostPolicy.postURL}/${presignedPostPolicy.formData.key}`,
formData: presignedPostPolicy.formData,
presignedUrl,
hasReachedStorageLimit: false,
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.1.27",
"version": "0.1.28",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.1.27",
"version": "0.1.28",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.1.27",
"version": "0.1.28",
"description": "Convenient library to display typebots on your React app",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
32 changes: 32 additions & 0 deletions packages/lib/s3/deprecated/generatePresignedUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { env } from '@typebot.io/env'
import { Client } from 'minio'

type GeneratePresignedUrlProps = {
filePath: string
fileType?: string
}

const tenMinutes = 10 * 60

export const generatePresignedUrl = async ({
filePath,
fileType,
}: GeneratePresignedUrlProps): Promise<string> => {
if (!env.S3_ENDPOINT || !env.S3_ACCESS_KEY || !env.S3_SECRET_KEY)
throw new Error(
'S3 not properly configured. Missing one of those variables: S3_ENDPOINT, S3_ACCESS_KEY, S3_SECRET_KEY'
)

const minioClient = new Client({
endPoint: env.S3_ENDPOINT,
port: env.S3_PORT,
useSSL: env.S3_SSL,
accessKey: env.S3_ACCESS_KEY,
secretKey: env.S3_SECRET_KEY,
region: env.S3_REGION,
})

return minioClient.presignedUrl('PUT', env.S3_BUCKET, filePath, tenMinutes, {
'Content-Type': fileType,
})
}

3 comments on commit 85272af

@vercel
Copy link

@vercel vercel bot commented on 85272af Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 85272af Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 85272af Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bot.grace.bj
bot.tobb.pro
cinecorn.com
ezbooking.ai
gniorder.com
help.taxt.co
kusamint.com
psmix.online
receita.info
rhino.cr8.ai
sheep.cr8.ai
snake.cr8.ai
svhm.mprs.in
tiger.cr8.ai
video.cr8.ai
webwhats.fun
webwhats.pro
whatsapp.web
yoda.riku.ai
zebra.cr8.ai
akademicq.com
alvodelas.com
bemestar.club
bot.krdfy.com
cat.hidden.sg
cgcassets.com
cnvhub.com.br
drapamela.com
facelabko.com
filmylogy.com
goldorayo.com
jerryyong.com
rabbit.cr8.ai
shop.mexwa.my
signup.cr8.ai
start.taxt.co
theusm.com.br
turkey.cr8.ai
vhpage.cr8.ai
vitamyway.com
whatchat.site
www.wiccom.it
am.nigerias.io
an.nigerias.io
app.yvon.earth
ar.nigerias.io
bot.enreso.org
bot.mail2wa.me
bot.rslabs.pro
bots.bng.tools
bots.bridge.ai
chad.gocto.com
chat.hayuri.id
chat.uprize.hu
chatgpt.lam.ee
chicken.cr8.ai
drayumi.social
gollum.riku.ai
gsbulletin.com
journey.cr8.ai
kopibayane.com
panther.cr7.ai
panther.cr8.ai
pay.sifuim.com
penguin.cr8.ai
segredomeu.com
semaknilai.com
talk.gocare.io
test.bot.gives
ticketfute.com
unicorn.cr8.ai
whats-app.chat
apo.nigerias.io
app.blogely.com
apr.nigerias.io
aso.nigerias.io
blackcan.cr8.ai
blackvip.online
bot.4display.nl
bot.a6t-you.com
bot.artiweb.app
bot.devitus.com
bot.reeplai.com
bot.scayver.com
bot.tc-mail.com
carspecs.lam.ee
chat.borang.net
chat.lalmon.com
chat.sureb4.com
conversawpp.com
eventhub.com.au
feiraododia.com
fitness.riku.ai
games.klujo.com
localove.online
projektelco.com
proscale.com.br
sellmycarbr.com
svhmapp.mprs.in
typebot.aloe.do

Please sign in to comment.