31
packages/lib/api/deleteFilesFromBucket.ts
Normal file
31
packages/lib/api/deleteFilesFromBucket.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { Client } from 'minio'
|
||||
|
||||
export const deleteFilesFromBucket = async ({
|
||||
urls,
|
||||
}: {
|
||||
urls: string[]
|
||||
}): Promise<void> => {
|
||||
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 ?? true,
|
||||
accessKey: env.S3_ACCESS_KEY,
|
||||
secretKey: env.S3_SECRET_KEY,
|
||||
region: env.S3_REGION,
|
||||
})
|
||||
|
||||
const bucket = env.S3_BUCKET ?? 'typebot'
|
||||
|
||||
return minioClient.removeObjects(
|
||||
bucket,
|
||||
urls
|
||||
.filter((url) => url.includes(env.S3_ENDPOINT as string))
|
||||
.map((url) => url.split(`/${bucket}/`)[1])
|
||||
)
|
||||
}
|
||||
@@ -24,9 +24,9 @@ export const generatePresignedUrl = ({
|
||||
accessKeyId: env.S3_ACCESS_KEY,
|
||||
secretAccessKey: env.S3_SECRET_KEY,
|
||||
region: env.S3_REGION,
|
||||
sslEnabled: env.S3_SSL,
|
||||
sslEnabled: env.S3_SSL ?? true,
|
||||
})
|
||||
const protocol = env.S3_SSL ? 'https' : 'http'
|
||||
const protocol = env.S3_SSL ?? true ? 'https' : 'http'
|
||||
const s3 = new S3({
|
||||
endpoint: new Endpoint(
|
||||
`${protocol}://${env.S3_ENDPOINT}${env.S3_PORT ? `:${env.S3_PORT}` : ''}`
|
||||
@@ -104,7 +104,7 @@ const deleteFilesFromBucket = async ({
|
||||
const minioClient = new Client({
|
||||
endPoint: env.S3_ENDPOINT,
|
||||
port: env.S3_PORT,
|
||||
useSSL: env.S3_SSL,
|
||||
useSSL: env.S3_SSL ?? true,
|
||||
accessKey: env.S3_ACCESS_KEY,
|
||||
secretKey: env.S3_SECRET_KEY,
|
||||
region: env.S3_REGION,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './utils'
|
||||
export * from './storage'
|
||||
export * from './generatePresignedUrl'
|
||||
export * from './encryption'
|
||||
|
||||
36
packages/lib/api/uploadFileToBucket.ts
Normal file
36
packages/lib/api/uploadFileToBucket.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { env } from '@typebot.io/env'
|
||||
import { Client } from 'minio'
|
||||
|
||||
type Props = {
|
||||
fileName: string
|
||||
file: Buffer
|
||||
mimeType: string
|
||||
}
|
||||
|
||||
export const uploadFileToBucket = async ({
|
||||
fileName,
|
||||
file,
|
||||
mimeType,
|
||||
}: Props): 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,
|
||||
})
|
||||
|
||||
await minioClient.putObject(env.S3_BUCKET, fileName, file, {
|
||||
'Content-Type': mimeType,
|
||||
})
|
||||
|
||||
return `http${env.S3_SSL ? 's' : ''}://${env.S3_ENDPOINT}${
|
||||
env.S3_PORT ? `:${env.S3_PORT}` : ''
|
||||
}/${env.S3_BUCKET}/${fileName}`
|
||||
}
|
||||
25
packages/lib/computeTypingDuration.ts
Normal file
25
packages/lib/computeTypingDuration.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
TypingEmulation,
|
||||
defaultSettings,
|
||||
} from '@typebot.io/schemas/features/typebot/settings'
|
||||
|
||||
type Props = {
|
||||
bubbleContent: string
|
||||
typingSettings?: TypingEmulation
|
||||
}
|
||||
|
||||
export const computeTypingDuration = ({
|
||||
bubbleContent,
|
||||
typingSettings = defaultSettings({ isBrandingEnabled: false })
|
||||
.typingEmulation,
|
||||
}: Props) => {
|
||||
let wordCount = bubbleContent.match(/(\w+)/g)?.length ?? 0
|
||||
if (wordCount === 0) wordCount = bubbleContent.length
|
||||
const typedWordsPerMinute = typingSettings.speed
|
||||
let typingTimeout = typingSettings.enabled
|
||||
? (wordCount / typedWordsPerMinute) * 60000
|
||||
: 0
|
||||
if (typingTimeout > typingSettings.maxDelay * 1000)
|
||||
typingTimeout = typingSettings.maxDelay * 1000
|
||||
return typingTimeout
|
||||
}
|
||||
@@ -31,6 +31,7 @@ export const parseTestTypebot = (
|
||||
isArchived: false,
|
||||
isClosed: false,
|
||||
resultsTablePreferences: null,
|
||||
whatsAppPhoneNumberId: null,
|
||||
variables: [{ id: 'var1', name: 'var1' }],
|
||||
...partialTypebot,
|
||||
edges: [
|
||||
|
||||
@@ -248,8 +248,6 @@ export const uploadFiles = async ({
|
||||
return urls
|
||||
}
|
||||
|
||||
declare const window: any
|
||||
|
||||
export const hasValue = (
|
||||
value: string | undefined | null
|
||||
): value is NonNullable<string> =>
|
||||
|
||||
Reference in New Issue
Block a user