Skip to content

Commit

Permalink
fix: delete file not delete attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinko committed Nov 20, 2024
1 parent 91fe7d5 commit 05f47cb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/server/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs, { unlink, stat, writeFile } from 'fs/promises';
import path from 'path';
import { cache } from "@/lib/cache";
import sharp from "sharp";
import { prisma } from "../prisma";

export class FileService {
public static async getS3Client() {
Expand Down Expand Up @@ -86,6 +87,10 @@ export class FileService {
await s3ClientInstance.send(command);
} else {
const filepath = path.join(process.cwd(), `${UPLOAD_FILE_PATH}/` + api_attachment_path.replace('/api/file/', ""));
const attachmentPath = await prisma.attachments.findFirst({ where: { path: api_attachment_path } })
if (attachmentPath) {
await prisma.attachments.delete({ where: { id: attachmentPath.id } })
}
if ('jpeg/jpg/png/bmp/tiff/tif/webp/svg'.includes(api_attachment_path.split('.')[1]?.replace('.', '')?.toLowerCase() ?? '')) {
try {
await unlink(path.join(process.cwd(), `${UPLOAD_FILE_PATH}/thumbnail_` + api_attachment_path.replace('/api/file/', "")));
Expand Down

0 comments on commit 05f47cb

Please sign in to comment.