feat: implementation
This commit is contained in:
37
app/api/parse/route.ts
Normal file
37
app/api/parse/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Response } from '@/utils/data';
|
||||
import { parser } from '@/utils/parser';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
if (!req.headers.get('content-type')?.startsWith('multipart/form-data')) {
|
||||
return new NextResponse('This API only accepts FormData.', {
|
||||
status: 415
|
||||
});
|
||||
}
|
||||
|
||||
const data = await req.formData();
|
||||
|
||||
const file = data.get('File');
|
||||
|
||||
if (!file || !(file instanceof File)) {
|
||||
return new NextResponse('No file provided', {
|
||||
status: 400
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedText = await parser(file);
|
||||
|
||||
const response: Response = {
|
||||
text: parsedText
|
||||
};
|
||||
|
||||
return new NextResponse(JSON.stringify(response), {
|
||||
status: 200
|
||||
});
|
||||
} catch (err) {
|
||||
return new NextResponse('Failed to parse PDF', {
|
||||
status: 500
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
app/favicon.ico
Normal file
BIN
app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
73
app/globals.css
Normal file
73
app/globals.css
Normal file
@@ -0,0 +1,73 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 255, 255, 255;
|
||||
--background-end-rgb: 0, 0, 255;
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
to bottom right,
|
||||
transparent,
|
||||
rgb(var(--background-end-rgb))
|
||||
)
|
||||
rgb(var(--background-start-rgb));
|
||||
}
|
||||
|
||||
input {
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dashboard {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 60vw;
|
||||
height: 80vh;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 15px;
|
||||
padding: 20px;
|
||||
box-shadow: 2px 2px 10px rgba(0, 0, 0, 5);
|
||||
background-color: white;
|
||||
gap: 20px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
border: 1px solid #ccc;
|
||||
overflow: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.button {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
max-width: 200px;
|
||||
}
|
||||
19
app/layout.tsx
Normal file
19
app/layout.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import type { Metadata } from 'next';
|
||||
import './globals.css';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'PDF text parser',
|
||||
description: 'Get the text content a PDF file in the browser (demo)'
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang='en'>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
11
app/page.tsx
Normal file
11
app/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import Dashboard from '@/components/Dashboard';
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
<Dashboard />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user