Adding methods to delete backups on remote storage s3 and local. Some refactoring on models db and adding common.ts model with createdAt, updatedAt, and deletedAt.

This commit is contained in:
charlesgauthereau
2025-08-29 15:31:23 +02:00
parent c8da2579e8
commit 45e3b31fda
48 changed files with 310 additions and 148 deletions
+40
View File
@@ -68,6 +68,46 @@ export async function createBucketIfNotExists(bucketName: string) {
}
}
/**
* Delete a file from a bucket
* @param bucketName name of the bucket
* @param fileName name of the file
* @returns true if deleted, false if not
*/
export async function deleteFileFromBucket({
bucketName,
fileName,
}: {
bucketName: string;
fileName: string;
}): Promise<boolean> {
const s3Client = await getS3Client();
try {
const fileExists = await checkFileExistsInBucket({ bucketName, fileName });
if (!fileExists) {
console.warn(`File not found: ${bucketName}/${fileName}`);
return false;
}
await s3Client.removeObject(bucketName, fileName);
console.log(`Deleted file: ${bucketName}/${fileName}`);
return true;
} catch (error: any) {
console.error("Error deleting file from bucket:", {
bucketName,
fileName,
error: error.message,
});
return false;
}
}
/**
* Save file in S3 bucket
* @param bucketName name of the bucket