Skip to content

An AI-powered search engine with a generative UI

style: format code with prettier

Yoshiki Miura6b98cea0d14d
diff --git a/app/api/upload/route.ts b/app/api/upload/route.ts
index aa508a38..8f344296 100644
--- a/app/api/upload/route.ts
+++ b/app/api/upload/route.ts
@@ -3,7 +3,11 @@ import { NextRequest, NextResponse } from 'next/server'
import { PutObjectCommand } from '@aws-sdk/client-s3'
import { getCurrentUserId } from '@/lib/auth/get-current-user'
-import { getR2Client, R2_BUCKET_NAME, R2_PUBLIC_URL } from '@/lib/storage/r2-client'
+import {
+ getR2Client,
+ R2_BUCKET_NAME,
+ R2_PUBLIC_URL
+} from '@/lib/storage/r2-client'
const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
const ALLOWED_TYPES = ['image/jpeg', 'image/png', 'application/pdf']
@@ -57,25 +61,23 @@ function sanitizeFilename(filename: string) {
return filename.replace(/[^a-z0-9.\-_]/gi, '_').toLowerCase()
}
-async function uploadFileToR2(
- file: File,
- userId: string,
- chatId: string
-) {
+async function uploadFileToR2(file: File, userId: string, chatId: string) {
const sanitizedFileName = sanitizeFilename(file.name)
const filePath = `${userId}/chats/${chatId}/${Date.now()}-${sanitizedFileName}`
-
+
try {
const buffer = Buffer.from(await file.arrayBuffer())
const r2Client = getR2Client()
-
- await r2Client.send(new PutObjectCommand({
- Bucket: R2_BUCKET_NAME,
- Key: filePath,
- Body: buffer,
- ContentType: file.type,
- CacheControl: 'max-age=3600'
- }))
+
+ await r2Client.send(
+ new PutObjectCommand({
+ Bucket: R2_BUCKET_NAME,
+ Key: filePath,
+ Body: buffer,
+ ContentType: file.type,
+ CacheControl: 'max-age=3600'
+ })
+ )
const publicUrl = `${R2_PUBLIC_URL}/${filePath}`
diff --git a/lib/storage/r2-client.ts b/lib/storage/r2-client.ts
index dd4d59b8..8289d3c3 100644
--- a/lib/storage/r2-client.ts
+++ b/lib/storage/r2-client.ts
@@ -28,4 +28,4 @@ export function getR2Client(): S3Client {
})
return _r2Client
-}
\ No newline at end of file
+}