-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/thiagobarbosa/ai-chatbot-wi…
…th-redis into fix-image-preview-on-chat
- Loading branch information
Showing
20 changed files
with
671 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ build | |
# misc | ||
.DS_Store | ||
*.pem | ||
.idea | ||
|
||
# debug | ||
npm-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import { put } from "@vercel/blob"; | ||
import { NextResponse } from "next/server"; | ||
import { z } from "zod"; | ||
import { put } from '@vercel/blob' | ||
import { NextResponse } from 'next/server' | ||
import { z } from 'zod' | ||
|
||
import { auth } from "@/app/(auth)/auth"; | ||
import { auth } from '@/app/(auth)/auth' | ||
|
||
const FileSchema = z.object({ | ||
file: z | ||
.instanceof(File) | ||
.refine((file) => file.size <= 5 * 1024 * 1024, { | ||
message: "File size should be less than 5MB", | ||
message: 'File size should be less than 5MB', | ||
}) | ||
.refine( | ||
(file) => | ||
["image/jpeg", "image/png", "application/pdf"].includes(file.type), | ||
['image/jpeg', 'image/png', 'application/pdf'].includes(file.type), | ||
{ | ||
message: "File type should be JPEG, PNG, or PDF", | ||
message: 'File type should be JPEG, PNG, or PDF', | ||
}, | ||
), | ||
}); | ||
}) | ||
|
||
export async function POST(request: Request) { | ||
const session = await auth(); | ||
const session = await auth() | ||
|
||
if (!session) { | ||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
if (request.body === null) { | ||
return new Response("Request body is empty", { status: 400 }); | ||
return new Response('Request body is empty', { status: 400 }) | ||
} | ||
|
||
try { | ||
const formData = await request.formData(); | ||
const file = formData.get("file") as File; | ||
const formData = await request.formData() | ||
const file = formData.get('file') as File | ||
|
||
if (!file) { | ||
return NextResponse.json({ error: "No file uploaded" }, { status: 400 }); | ||
return NextResponse.json({ error: 'No file uploaded' }, { status: 400 }) | ||
} | ||
|
||
const validatedFile = FileSchema.safeParse({ file }); | ||
const validatedFile = FileSchema.safeParse({ file }) | ||
|
||
if (!validatedFile.success) { | ||
const errorMessage = validatedFile.error.errors | ||
.map((error) => error.message) | ||
.join(", "); | ||
.join(', ') | ||
|
||
return NextResponse.json({ error: errorMessage }, { status: 400 }); | ||
return NextResponse.json({ error: errorMessage }, { status: 400 }) | ||
} | ||
|
||
const filename = file.name; | ||
const fileBuffer = await file.arrayBuffer(); | ||
const filename = file.name | ||
const fileBuffer = await file.arrayBuffer() | ||
|
||
try { | ||
const data = await put(`${filename}`, fileBuffer, { | ||
access: "public", | ||
}); | ||
const data = await put(`chats/${filename}`, fileBuffer, { | ||
access: 'public', | ||
}) | ||
|
||
return NextResponse.json(data); | ||
} catch (error) { | ||
return NextResponse.json({ error: "Upload failed" }, { status: 500 }); | ||
return NextResponse.json(data) | ||
} catch (error: any) { | ||
return NextResponse.json({ error: `Failed to upload file: ${error.message}` }, { status: 500 }) | ||
} | ||
} catch (error) { | ||
} catch (error: any) { | ||
return NextResponse.json( | ||
{ error: "Failed to process request" }, | ||
{ error: `An error occurred while processing your request: ${error.message}` }, | ||
{ status: 500 }, | ||
); | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,11 @@ | |
} | ||
} | ||
|
||
img[alt=md-image] { | ||
width: 150px; | ||
margin: 1rem auto; | ||
} | ||
|
||
.ProseMirror { | ||
outline: none; | ||
} | ||
|
Oops, something went wrong.