Files
classroomio/apps/dashboard/src/lib/utils/services/upload.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

29 lines
740 B
TypeScript

import { classroomio } from './api';
/**
* Uploads an image file to R2 storage and returns the public URL
* @param file - The image file to upload
* @returns The public URL of the uploaded image
* @throws Error if upload fails
*/
export async function uploadImage(file: File): Promise<string> {
try {
const response = await classroomio.media.image.$post({
form: {
file: file
}
});
const data = await response.json();
if (!data.success || !data.url) {
const errorMessage = 'error' in data ? data.error : 'Failed to upload image';
throw new Error(errorMessage);
}
return data.url;
} catch (error) {
console.error('Error uploading image:', error);
throw error;
}
}