🚑 (upload) Fix upload in embed
This commit is contained in:
@ -9,7 +9,7 @@ import {
|
|||||||
} from '@typebot.io/schemas'
|
} from '@typebot.io/schemas'
|
||||||
import { byId, isDefined } from '@typebot.io/lib'
|
import { byId, isDefined } from '@typebot.io/lib'
|
||||||
import { z } from 'zod'
|
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 { env } from '@typebot.io/env'
|
||||||
import prisma from '@typebot.io/lib/prisma'
|
import prisma from '@typebot.io/lib/prisma'
|
||||||
|
|
||||||
@ -34,7 +34,6 @@ export const getUploadUrl = publicProcedure
|
|||||||
.output(
|
.output(
|
||||||
z.object({
|
z.object({
|
||||||
presignedUrl: z.string(),
|
presignedUrl: z.string(),
|
||||||
formData: z.record(z.string(), z.any()),
|
|
||||||
hasReachedStorageLimit: z.boolean(),
|
hasReachedStorageLimit: z.boolean(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -62,15 +61,13 @@ export const getUploadUrl = publicProcedure
|
|||||||
message: 'File upload block not found',
|
message: 'File upload block not found',
|
||||||
})
|
})
|
||||||
|
|
||||||
const presignedPostPolicy = await generatePresignedPostPolicy({
|
const presignedUrl = await generatePresignedUrl({
|
||||||
fileType,
|
fileType,
|
||||||
filePath,
|
filePath,
|
||||||
maxFileSize: env.NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
presignedUrl: `${presignedPostPolicy.postURL}/${presignedPostPolicy.formData.key}`,
|
presignedUrl,
|
||||||
formData: presignedPostPolicy.formData,
|
|
||||||
hasReachedStorageLimit: false,
|
hasReachedStorageLimit: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.1.27",
|
"version": "0.1.28",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/nextjs",
|
"name": "@typebot.io/nextjs",
|
||||||
"version": "0.1.27",
|
"version": "0.1.28",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.1.27",
|
"version": "0.1.28",
|
||||||
"description": "Convenient library to display typebots on your React app",
|
"description": "Convenient library to display typebots on your React app",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
32
packages/lib/s3/deprecated/generatePresignedUrl.ts
Normal file
32
packages/lib/s3/deprecated/generatePresignedUrl.ts
Normal file
@ -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,
|
||||||
|
})
|
||||||
|
}
|
Reference in New Issue
Block a user