made a pagination service

This commit is contained in:
2025-11-29 12:04:50 +05:30
parent e0b841b437
commit 264f2fa29c
6 changed files with 149 additions and 18 deletions

View File

@@ -38,16 +38,25 @@ async function uploadToS3(buffer: Buffer, mimeType: string, originalName: string
let s3Key: string;
// If existing URL provided, use the same S3 key to replace the file
// if (existingUrl) {
// s3Key = getS3KeyFromUrl(existingUrl);
// // Delete existing file first
// await deleteFromS3(s3Key);
// } else {
// // Generate new unique key for new file
// const uniqueKey = `${crypto.randomUUID()}_${originalName}`;
// s3Key = `${prefix}/${uniqueKey}`;
// }
if (existingUrl) {
s3Key = getS3KeyFromUrl(existingUrl);
// Delete existing file first
await deleteFromS3(s3Key);
} else {
// Generate new unique key for new file
const uniqueKey = `${crypto.randomUUID()}_${originalName}`;
s3Key = `${prefix}/${uniqueKey}`;
// Delete old file, but DO NOT reuse its name
const oldKey = getS3KeyFromUrl(existingUrl);
await deleteFromS3(oldKey);
}
// Create new key always
const uniqueKey = `${crypto.randomUUID()}_${originalName}`;
s3Key = `${prefix}/${uniqueKey}`;
// Upload new file (replaces existing if same key)
await s3.upload({
Bucket: config.aws.bucketName,