Compare commits
1 Commits
security/a
...
fix/delete
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fcd0e8688 |
@@ -9,7 +9,7 @@ import { generateUID } from "@kan/shared/utils";
|
|||||||
|
|
||||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
import { assertUserInWorkspace } from "../utils/auth";
|
import { assertUserInWorkspace } from "../utils/auth";
|
||||||
import { generateUploadUrl } from "../utils/s3";
|
import { deleteObject, generateUploadUrl } from "../utils/s3";
|
||||||
|
|
||||||
export const attachmentRouter = createTRPCRouter({
|
export const attachmentRouter = createTRPCRouter({
|
||||||
generateUploadUrl: protectedProcedure
|
generateUploadUrl: protectedProcedure
|
||||||
@@ -189,6 +189,18 @@ export const attachmentRouter = createTRPCRouter({
|
|||||||
|
|
||||||
await assertUserInWorkspace(ctx.db, userId, workspaceId);
|
await assertUserInWorkspace(ctx.db, userId, workspaceId);
|
||||||
|
|
||||||
|
const bucket = process.env.NEXT_PUBLIC_ATTACHMENTS_BUCKET_NAME;
|
||||||
|
if (bucket) {
|
||||||
|
try {
|
||||||
|
await deleteObject(bucket, attachment.s3Key);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
`Failed to delete attachment from S3: ${attachment.s3Key}`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await cardAttachmentRepo.softDelete(ctx.db, {
|
await cardAttachmentRepo.softDelete(ctx.db, {
|
||||||
attachmentId: attachment.id,
|
attachmentId: attachment.id,
|
||||||
deletedAt: new Date(),
|
deletedAt: new Date(),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
DeleteObjectCommand,
|
||||||
GetObjectCommand,
|
GetObjectCommand,
|
||||||
PutObjectCommand,
|
PutObjectCommand,
|
||||||
S3Client,
|
S3Client,
|
||||||
@@ -56,3 +57,13 @@ export async function generateDownloadUrl(
|
|||||||
{ expiresIn },
|
{ expiresIn },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteObject(bucket: string, key: string) {
|
||||||
|
const client = createS3Client();
|
||||||
|
await client.send(
|
||||||
|
new DeleteObjectCommand({
|
||||||
|
Bucket: bucket,
|
||||||
|
Key: key,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user