diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 01:44:45 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-07 01:44:45 +0000 |
| commit | 90f79a7a691943a496f67f01c1e493256070e4de (patch) | |
| tree | 37275fde3ae08c2bca384fbbc8eb378de7e39230 /lib/tech-vendors | |
| parent | fbb3b7f05737f9571b04b0a8f4f15c0928de8545 (diff) | |
(대표님) 변경사항 20250707 10시 43분 - unstaged 변경사항 추가
Diffstat (limited to 'lib/tech-vendors')
| -rw-r--r-- | lib/tech-vendors/service.ts | 38 |
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) { |
