* feat: setup secure presigned uploads and downloads * clean up * update lock * Get presigned url finally working * 557: Migrate backend to hono + ts * chore: update Dockerfile and package.json for backend configuration * add dev command * remove unused packages * Enhance backend API and frontend components for course management - Updated CORS configuration in the backend to allow specific methods and headers. - Refactored lesson download endpoint to use a new route for PDF downloads. - Removed unused certificate download functionality from the lesson router. - Updated frontend components to reflect changes in API endpoints and improve video upload functionality. - Introduced new video upload component and adjusted video handling in lesson materials. - Cleaned up unnecessary imports and optimized component structure for better performance. * PR cleanups * Enhance email configuration by adding SMTP_SENDER environment variable - Updated docker-compose.yaml to include SMTP_SENDER. - Modified Dockerfile to accept SMTP_SENDER as an argument. - Updated environment schema in env.ts to define SMTP_SENDER as optional. - Adjusted mail service to use SMTP_SENDER for the email 'from' field. - Updated documentation to reflect the new SMTP_SENDER variable. * Remove debug log statement from sendEmail function --------- Co-authored-by: Iniubong Obonguko <[email protected]>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import {
|
|
DeleteObjectCommand,
|
|
DeleteObjectCommandInput,
|
|
GetObjectCommand,
|
|
GetObjectCommandInput,
|
|
PutObjectCommand,
|
|
PutObjectCommandInput,
|
|
S3Client
|
|
} from '@aws-sdk/client-s3';
|
|
|
|
import { CLOUDFLARE } from '$src/constants';
|
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
|
|
export type GetSignedUrlParameters = Parameters<typeof getSignedUrl>;
|
|
|
|
export const s3Client = new S3Client({
|
|
region: 'auto',
|
|
endpoint: `https://${CLOUDFLARE.CONFIGS.ACCOUNT_ID}.r2.cloudflarestorage.com`,
|
|
credentials: {
|
|
accessKeyId: CLOUDFLARE.CONFIGS.ACCESS_KEY,
|
|
secretAccessKey: CLOUDFLARE.CONFIGS.SECRET_ACCESS_KEY
|
|
}
|
|
});
|
|
|
|
export async function uploadToS3(
|
|
params: PutObjectCommandInput
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
try {
|
|
await s3Client.send(new PutObjectCommand(params));
|
|
return { success: true };
|
|
} catch (error) {
|
|
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
|
|
}
|
|
}
|
|
|
|
export async function getFromS3(
|
|
params: GetObjectCommandInput
|
|
): Promise<{ success: boolean; data?: any; error?: string }> {
|
|
try {
|
|
const data = await s3Client.send(new GetObjectCommand(params));
|
|
return { success: true, data };
|
|
} catch (error) {
|
|
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
|
|
}
|
|
}
|
|
|
|
export async function deleteFromS3(
|
|
params: DeleteObjectCommandInput
|
|
): Promise<{ success: boolean; error?: string }> {
|
|
try {
|
|
await s3Client.send(new DeleteObjectCommand(params));
|
|
return { success: true };
|
|
} catch (error) {
|
|
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
|
|
}
|
|
}
|