Files
classroomio/apps/api/src/routes/media/media.ts
T
Rotimi Best 4b52906445 feat: enhance API route naming conventions and structure
- Added comprehensive guidelines for API route naming and structure in `ROUTE_NAMING_BEST_PRACTICES.md`.
- Updated `ARCHITECHTURE.md` to reference the new best practices document.
- Refactored course-related routes to follow new naming conventions, including changes to endpoint paths and validation schemas.
- Removed the deprecated course clone route and integrated cloning functionality directly into the course routes.
- Adjusted various API methods to ensure consistent usage of HTTP methods and parameter structures across the application.
2025-12-05 17:24:16 +01:00

30 lines
843 B
TypeScript

import { AppError, ErrorCodes } from '@api/utils/errors';
import { Hono } from '@api/utils/hono';
import { authMiddleware } from '@api/middlewares/auth';
import { handleError } from '@api/utils/errors';
import { uploadImage } from '@api/services/media';
export const mediaRouter = new Hono().post('/image', authMiddleware, async (c) => {
try {
const body = await c.req.parseBody();
const file = body.file;
if (!file || !(file instanceof File)) {
throw new AppError(new Error('No file provided'), ErrorCodes.VALIDATION_ERROR, 400);
}
const result = await uploadImage(file);
return c.json({
success: true,
url: result.url,
fileKey: result.fileKey,
message: 'Image uploaded successfully'
});
} catch (error) {
return handleError(c, error, 'Failed to upload image');
}
});