diff options
| author | Mert Demir <mertd@users.noreply.github.com> | 2024-02-01 07:00:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-31 17:00:19 -0500 |
| commit | 08d75fd75c063bd17d2471b263452b490910338b (patch) | |
| tree | 8374575ab7ad02327fa3a4fbfa5d04415d3944d6 /src | |
| parent | e6467b41fccefe1ceb39dd1ed6343290e152be85 (diff) | |
Support for additional S3 providers (#71)
* support for other s3 providers
* remove redundant route options
* use type safe env
* prettier
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/api/s3-upload/route.ts | 4 | ||||
| -rw-r--r-- | src/components/expense-documents-input.tsx | 4 | ||||
| -rw-r--r-- | src/lib/env.ts | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/src/app/api/s3-upload/route.ts b/src/app/api/s3-upload/route.ts index 567cd40..ee3fb72 100644 --- a/src/app/api/s3-upload/route.ts +++ b/src/app/api/s3-upload/route.ts @@ -1,4 +1,5 @@ import { randomId } from '@/lib/api' +import { env } from '@/lib/env' import { POST as route } from 'next-s3-upload/route' export const POST = route.configure({ @@ -8,4 +9,7 @@ export const POST = route.configure({ const random = randomId() return `document-${timestamp}-${random}${extension.toLowerCase()}` }, + endpoint: env.S3_UPLOAD_ENDPOINT, + // forcing path style is only necessary for providers other than AWS + forcePathStyle: !!env.S3_UPLOAD_ENDPOINT, }) diff --git a/src/components/expense-documents-input.tsx b/src/components/expense-documents-input.tsx index b9cda33..7b69a6d 100644 --- a/src/components/expense-documents-input.tsx +++ b/src/components/expense-documents-input.tsx @@ -18,7 +18,7 @@ import { useToast } from '@/components/ui/use-toast' import { randomId } from '@/lib/api' import { ExpenseFormValues } from '@/lib/schemas' import { Loader2, Plus, Trash, X } from 'lucide-react' -import { getImageData, useS3Upload } from 'next-s3-upload' +import { getImageData, usePresignedUpload } from 'next-s3-upload' import Image from 'next/image' import { useEffect, useState } from 'react' @@ -29,7 +29,7 @@ type Props = { export function ExpenseDocumentsInput({ documents, updateDocuments }: Props) { const [pending, setPending] = useState(false) - const { FileInput, openFileDialog, uploadToS3 } = useS3Upload() + const { FileInput, openFileDialog, uploadToS3 } = usePresignedUpload() // use presigned uploads to addtionally support providers other than AWS const { toast } = useToast() const handleFileChange = async (file: File) => { diff --git a/src/lib/env.ts b/src/lib/env.ts index 33b835d..f1d59db 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -17,12 +17,14 @@ const envSchema = z S3_UPLOAD_SECRET: z.string().optional(), S3_UPLOAD_BUCKET: z.string().optional(), S3_UPLOAD_REGION: z.string().optional(), + S3_UPLOAD_ENDPOINT: z.string().optional(), NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT: z.coerce.boolean().default(false), OPENAI_API_KEY: z.string().optional(), }) .superRefine((env, ctx) => { if ( env.NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS && + // S3_UPLOAD_ENDPOINT is fully optional as it will only be used for providers other than AWS (!env.S3_UPLOAD_BUCKET || !env.S3_UPLOAD_KEY || !env.S3_UPLOAD_REGION || |
