summaryrefslogtreecommitdiff
path: root/lib/tech-vendors
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tech-vendors')
-rw-r--r--lib/tech-vendors/service.ts38
1 files changed, 5 insertions, 33 deletions
diff --git a/lib/tech-vendors/service.ts b/lib/tech-vendors/service.ts
index 71d47e05..da4a44eb 100644
--- a/lib/tech-vendors/service.ts
+++ b/lib/tech-vendors/service.ts
@@ -36,11 +36,10 @@ import type {
import { asc, desc, ilike, inArray, and, or, eq, isNull, not } from "drizzle-orm";
import path from "path";
-import fs from "fs/promises";
-import { randomUUID } from "crypto";
import { sql } from "drizzle-orm";
import { users } from "@/db/schema/users";
import { decryptWithServerAction } from "@/components/drm/drmUtils";
+import { deleteFile, saveDRMFile } from "../file-stroage";
/* -----------------------------------------------------
1) 조회 관련
@@ -266,34 +265,16 @@ async function storeTechVendorFiles(
files: File[],
attachmentType: string
) {
- const vendorDir = path.join(
- process.cwd(),
- "public",
- "tech-vendors",
- String(vendorId)
- );
- await fs.mkdir(vendorDir, { recursive: true });
for (const file of files) {
- // Convert file to buffer
- // DRM 복호화 시도 및 버퍼 변환
- const decryptedData = await decryptWithServerAction(file);
- const buffer = Buffer.from(decryptedData);
-
- // Generate a unique filename
- const uniqueName = `${randomUUID()}-${file.name}`;
- const relativePath = path.join("tech-vendors", String(vendorId), uniqueName);
- const absolutePath = path.join(process.cwd(), "public", relativePath);
-
- // Write to disk
- await fs.writeFile(absolutePath, buffer);
+ const saveResult = await saveDRMFile(file, decryptWithServerAction, `tech-vendors/${vendorId}`)
// Insert attachment record
await tx.insert(techVendorAttachments).values({
vendorId,
fileName: file.name,
- filePath: "/" + relativePath.replace(/\\/g, "/"),
+ filePath: saveResult.publicPath,
attachmentType,
});
}
@@ -1232,17 +1213,8 @@ export async function cleanupTechTempFiles(fileName: string) {
'use server';
try {
- const tempDir = path.join(process.cwd(), 'tmp');
- const filePath = path.join(tempDir, fileName);
-
- try {
- // 파일 존재 확인
- await fs.access(filePath, fs.constants.F_OK);
- // 파일 삭제
- await fs.unlink(filePath);
- } catch {
- // 파일이 없으면 무시
- }
+
+ await deleteFile(`tmp/${fileName}`)
return { success: true };
} catch (error) {