chore: attachment 인터페이스 수정
This commit is contained in:
@@ -7,6 +7,7 @@ import { handleTusUpload } from "@/entities/tus";
|
||||
import { AttachmentApi, type Attachment } from "@/entities/attachment";
|
||||
import type { PostFormData, PostUpdateFormData } from "@/entities/post";
|
||||
import { setCookie, useAlertStore, useMenuStore } from "@/shared/lib";
|
||||
import type { BbsType } from "@/shared/store/menu-store";
|
||||
|
||||
function WithPreviewFileUploader<T extends PostFormData | PostUpdateFormData>({
|
||||
form,
|
||||
@@ -21,6 +22,17 @@ function WithPreviewFileUploader<T extends PostFormData | PostUpdateFormData>({
|
||||
const [thumbnailUrl, setThumbnailUrl] = useState("");
|
||||
const [progress, setProgress] = useState(0);
|
||||
|
||||
const fileAccept = (bbsTypeCd: BbsType) => {
|
||||
switch (bbsTypeCd) {
|
||||
case "BBSIMAGE":
|
||||
return ".jpeg,.jpg,.png";
|
||||
case "BBSMOVIE":
|
||||
return ".mp4,.mov,.avi,.wmv,.mkv";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
const handleTusResponse = async (res: HttpResponse) => {
|
||||
const fileInfo = res.getHeader("X-File-Info");
|
||||
if (
|
||||
@@ -33,7 +45,13 @@ function WithPreviewFileUploader<T extends PostFormData | PostUpdateFormData>({
|
||||
const { atflCd, atflId } = JSON.parse(fileInfo) ?? {};
|
||||
if (atflCd) form.setValue("atflCd" as FieldPath<T>, atflCd);
|
||||
if (atflId) {
|
||||
const imageUrl = await AttachmentApi.getImageUrl(atflId);
|
||||
let imageUrl = "";
|
||||
if (bbsInfo?.bbsTypeCd === "BBSIMAGE") {
|
||||
imageUrl = await AttachmentApi.getImageUrlByAtflId(atflId);
|
||||
}
|
||||
if (bbsInfo?.bbsTypeCd === "BBSMOVIE") {
|
||||
imageUrl = await AttachmentApi.getMovieThumbnailUrl(atflId);
|
||||
}
|
||||
setThumbnailUrl(imageUrl);
|
||||
}
|
||||
};
|
||||
@@ -67,7 +85,7 @@ function WithPreviewFileUploader<T extends PostFormData | PostUpdateFormData>({
|
||||
useEffect(() => {
|
||||
if (!attachmentData || attachmentData.length === 0) return;
|
||||
(async () => {
|
||||
const imageUrl = await AttachmentApi.getImageUrl(
|
||||
const imageUrl = await AttachmentApi.getImageUrlByAtflId(
|
||||
attachmentData[0]?.atflId as string,
|
||||
);
|
||||
setThumbnailUrl(imageUrl);
|
||||
@@ -77,8 +95,8 @@ function WithPreviewFileUploader<T extends PostFormData | PostUpdateFormData>({
|
||||
return (
|
||||
<FileUploader
|
||||
id="atflCd"
|
||||
className="!h-auto !max-w-none flex-col !items-start gap-4"
|
||||
accept=".jpeg,.jpg,.png"
|
||||
className="!h-auto !max-w-none flex-col !items-start gap-4 [&_.file-uploader-label]:h-[3.2rem]"
|
||||
accept={fileAccept(bbsInfo?.bbsTypeCd as BbsType)}
|
||||
onUpload={onUpload}
|
||||
customPreview={
|
||||
<Label htmlFor="atflCd">
|
||||
|
||||
Reference in New Issue
Block a user