import { PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'; //import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; // Optional if we want signed URLs import r2Client from '../config/storage.js'; const BUCKET_NAME = process.env.R2_BUCKET_NAME; // Upload File to R2 export const uploadToR2 = async (fileBuffer, fileName, mimeType) => { const key = `tenders/${Date.now()}_${fileName.replace(/\s+/g, '_')}`; const command = new PutObjectCommand({ Bucket: BUCKET_NAME, Key: key, Body: fileBuffer, ContentType: mimeType }); await r2Client.send(command); return key; }; // Get File Stream from R2 export const getFileStream = async (key) => { const command = new GetObjectCommand({ Bucket: BUCKET_NAME, Key: key }); const response = await r2Client.send(command); return response.Body; }; // Get Full Object from R2 (Modified to return full response) export const getFileObject = async (key) => { const command = new GetObjectCommand({ Bucket: BUCKET_NAME, Key: key }); return await r2Client.send(command); };