'use client'; import { useState } from 'react'; import { FoxFormLabel } from '@fox/core/components/fox-form-label'; import { FoxHelperText } from '@fox/core/components/fox-helper-text'; import styles from './board-attachment-field.module.scss'; import { FILE_MODULE, MAX_ATTACHMENT_BYTES, allowedExtensions, fileModuleAccept, isAllowedFileExtension, } from '@/lib/domain/file-module'; interface BoardAttachmentFieldProps { label?: string; /** 이미 저장돼 있는 첨부파일 식별자(수정 화면). 없으면 신규 등록이다. */ attachmentId?: string | null; } /** 다운로드 라우트 — 백엔드 파일 API를 중계한다(`boards/attachments/route.ts`). */ const ATTACHMENT_DOWNLOAD_PATH = '/boards/attachments'; /** * 첨부파일 입력 — 파일을 고르면 **폼과 함께 그대로 제출**되고, Server Action이 업로드한 뒤 * 게시물에 연결한다(브라우저에서 미리 업로드하지 않는다 — `_actions.ts` 주석 참조). * * 기존 첨부는 **다운로드 링크로만** 보여준다. 시안(A_BOA_008_p)은 `pic_0001.jpg 88KB`처럼 파일명과 * 용량을 표기하지만, **백엔드에 atchFileId로 파일 정보를 조회하는 API가 없어** 저장된 첨부의 * 이름·크기를 알 방법이 없다(업로드·다운로드·삭제·이미지·스트림만 존재). 그 API가 생기면 여기에 * 파일명·용량 표기와 개별 삭제 버튼을 붙이면 된다. * * 새 파일을 고르면 기존 첨부는 교체된다(백엔드 필드가 `atchFileId` 하나뿐이다). 파일을 고르지 * 않으면 기존 첨부가 그대로 유지된다. */ const OVERSIZE_MESSAGE = `첨부파일은 ${Math.floor( MAX_ATTACHMENT_BYTES / (1024 * 1024) )}MB 이하만 올릴 수 있습니다.`; const EXTENSION_MESSAGE = `${allowedExtensions(FILE_MODULE.board).join(', ')} 파일만 올릴 수 있습니다.`; export function BoardAttachmentField({ label = '첨부파일', attachmentId, }: BoardAttachmentFieldProps) { const [error, setError] = useState(undefined); return ( ); }