feat: better markdown code, api

This commit is contained in:
2024-03-02 17:11:07 +01:00
parent 854bc972eb
commit 94c2449602
5 changed files with 29 additions and 9 deletions

View File

@@ -0,0 +1,24 @@
import {ZCreateApiRequest} from "@/utils/types";
import db from "@/db";
import {code} from "@/db/schema";
import {randomString} from "util-utils";
import * as schema from "@/db/schema";
export async function POST(request: Request) {
if (request.headers.get('Authorization') !== process.env.AUTOMATA_UPLOAD_KEY)
return new Response('Unauthorized', {status: 401})
try {
const data = await ZCreateApiRequest.parseAsync(await request.json())
const written = await db.insert(code)
.values({
id: randomString(8),
...data
})
.returning({
snippetId: schema.code.id
})
return new Response(JSON.stringify(written[0].snippetId), {status: 200})
} catch (e) {
return new Response(`Invalid request ${e}`, {status: 400})
}
}

View File

@@ -43,13 +43,14 @@ export default async function Page({ params }: { params: { id: string } }) {
codeTagProps={{ className: 'codeHighlighter' }}
language={match[1]}
// eslint-disable-next-line react/no-children-prop
children={String(children).replace(/\n$/, '')}
children={String(children)}
/>
) : (
<code className={className} {...props} style={{
fontSize: '1rem',
backgroundColor: '#171717',
outline: '3px solid #171717'
outline: '3px solid #171717',
color: 'white',
}}>
{children}
</code>

View File

@@ -15,11 +15,6 @@ import Link from 'next/link';
import {useRouter} from "next-nprogress-bar";
import {usePathname} from "next/navigation";
/*const user = {
name: 'Jane Spoonfighter',
email: 'janspoon@fighter.dev',
image: 'https://raw.githubusercontent.com/mantinedev/mantine/master/.demo/avatars/avatar-5.png',
};*/
const links = [
{ link: '/', label: 'Create' },
{ link: '/md', label: 'Markdown' },

View File

@@ -4,7 +4,7 @@ import { authMiddleware } from "@clerk/nextjs";
// Please edit this to allow other routes to be public as needed.
// See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your Middleware
export default authMiddleware({
publicRoutes: ['/']
publicRoutes: ['/', '/api/create']
});
export const config = {

View File

@@ -8,7 +8,7 @@ const Providers = ({ children }: { children: React.ReactNode }) => {
{children}
<ProgressBar
height="4px"
color="#fffd00"
color="#228be6"
options={{ showSpinner: false }}
/>
</>