feat: base shortcut code

This commit is contained in:
2025-01-18 21:54:26 +01:00
parent a820b29ea9
commit 3abe88c7a2
29 changed files with 5982 additions and 123 deletions

50
app/api/shortcut/route.ts Normal file
View File

@@ -0,0 +1,50 @@
import { NextResponse } from 'next/server';
import { ShortcutsHandler } from '@utils/handler';
import { RequestSchema } from '@utils/types';
export async function POST(req: Request) {
try {
const body = await req.json();
const result = RequestSchema.safeParse(body);
if (!result.success) {
return NextResponse.json(
{
success: false,
message: 'Invalid request format.',
errors: result.error.errors
},
{ status: 400 }
);
}
const shortcutsHandler = new ShortcutsHandler();
const isValid = shortcutsHandler.validateRequest(result.data);
if (!isValid) {
return NextResponse.json(
{
success: false,
message: 'Unauthorized.'
},
{ status: 401 }
);
}
const response = await shortcutsHandler.processCommand(
result.data.command,
result.data.parameters
);
return NextResponse.json(response);
} catch (error) {
console.error('Error processing shortcuts request:', error);
return NextResponse.json(
{
success: false,
message: 'An error occurred while processing your request.'
},
{ status: 500 }
);
}
}