Skip to content

Commit

Permalink
UPDATE: deleting blinks deletes s3 image
Browse files Browse the repository at this point in the history
  • Loading branch information
anisharaz committed Aug 16, 2024
1 parent b62e221 commit 7a284b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/action/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use server";

import { Deletes3image } from "@/lib/AWS";
import prisma from "@/lib/db";
import { SolanaActionsSpecClass } from "@/lib/SolanaActionsSpecClass";
import { revalidatePath } from "next/cache";
Expand Down Expand Up @@ -90,12 +91,14 @@ export async function addBlinkData({
}
}

// TODO: add error handling
export async function DeleteBlink({ id }: { id: string }) {
const deletedBlink = await prisma.blinks.delete({
where: {
id: id,
},
});
await Deletes3image({ key: `bms/${deletedBlink.id}.jpg` });
revalidatePath(`/dashboard`);
return deletedBlink;
}
Expand Down
15 changes: 14 additions & 1 deletion lib/AWS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { S3Client } from "@aws-sdk/client-s3";
import { DeleteObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
export const s3Client = new S3Client({
region: "us-east-1",
Expand All @@ -24,3 +24,16 @@ export async function GetPreSignedUrl({ blinkid }: { blinkid: string }) {
});
return { url, fields, key };
}

export async function Deletes3image({ key }: { key: string }) {
try {
await s3Client.send(
new DeleteObjectCommand({
Bucket: "aaraz-main",
Key: key,
})
);
} catch (error) {
console.log(error);
}
}

0 comments on commit 7a284b4

Please sign in to comment.