2
0

feat(editor): Add file upload input

This commit is contained in:
Baptiste Arnaud
2022-06-12 17:34:33 +02:00
parent d4c52d47b3
commit 75365a0d82
48 changed files with 1022 additions and 587 deletions

View File

@ -1,7 +1,6 @@
import imageCompression from 'browser-image-compression'
import { Parser } from 'htmlparser2'
import { Block, Typebot } from 'models'
import { sendRequest } from 'utils'
export const fetcher = async (input: RequestInfo, init?: RequestInit) => {
const res = await fetch(input, init)
@ -37,26 +36,6 @@ export const toKebabCase = (value: string) => {
return matched.map((x) => x.toLowerCase()).join('-')
}
export const uploadFile = async (file: File, filePath: string) => {
const { data } = await sendRequest<{ presignedUrl: string }>(
`/api/storage/upload-url?filePath=${encodeURIComponent(filePath)}`
)
if (!data?.presignedUrl)
return {
url: null,
}
await fetch(data.presignedUrl, {
method: 'PUT',
body: file,
})
return {
url: data.presignedUrl.split('?')[0],
}
}
export const compressFile = async (file: File) => {
const options = {
maxSizeMB: 0.5,