7.10 제휴업소 일반(사진) 카테고리 전용 이미지 첨부/미리보기 규칙 o
This commit is contained in:
@@ -105,6 +105,8 @@ async function upsertBoards(admin) {
|
|||||||
{ name: "회원랭킹", slug: "ranking", description: "랭킹", type: "special", sortOrder: 14 },
|
{ name: "회원랭킹", slug: "ranking", description: "랭킹", type: "special", sortOrder: 14 },
|
||||||
{ name: "무료쿠폰", slug: "free-coupons", description: "쿠폰", type: "special", sortOrder: 15 },
|
{ name: "무료쿠폰", slug: "free-coupons", description: "쿠폰", type: "special", sortOrder: 15 },
|
||||||
{ name: "월간집계", slug: "monthly-stats", description: "월간 통계", type: "special", sortOrder: 16 },
|
{ name: "월간집계", slug: "monthly-stats", description: "월간 통계", type: "special", sortOrder: 16 },
|
||||||
|
// 제휴업소 일반(사진)
|
||||||
|
{ name: "제휴업소 일반(사진)", slug: "partners-photos", description: "사진 전용 게시판", type: "general", sortOrder: 17, requiredFields: { imageOnly: true, minImages: 1, maxImages: 10 } },
|
||||||
];
|
];
|
||||||
|
|
||||||
const created = [];
|
const created = [];
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ export async function POST(req: Request) {
|
|||||||
const { boardId, authorId, title, content, isAnonymous } = parsed.data;
|
const { boardId, authorId, title, content, isAnonymous } = parsed.data;
|
||||||
const board = await prisma.board.findUnique({ where: { id: boardId } });
|
const board = await prisma.board.findUnique({ where: { id: boardId } });
|
||||||
const requiresApproval = board?.requiresApproval ?? false;
|
const requiresApproval = board?.requiresApproval ?? false;
|
||||||
|
// 사진형 보드 필수 이미지 검증: content 내 이미지 링크 최소 1개
|
||||||
|
const isImageOnly = (board?.requiredFields as any)?.imageOnly;
|
||||||
|
const minImages = (board?.requiredFields as any)?.minImages ?? 0;
|
||||||
|
if (isImageOnly || minImages > 0) {
|
||||||
|
const imageLinks = (content.match(/!\[[^\]]*\]\([^\)]+\)/g) ?? []).length;
|
||||||
|
if (imageLinks < (minImages || 1)) {
|
||||||
|
return NextResponse.json({ error: { message: `이미지 최소 ${minImages || 1}개 필요` } }, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
const post = await prisma.post.create({
|
const post = await prisma.post.create({
|
||||||
data: {
|
data: {
|
||||||
boardId,
|
boardId,
|
||||||
|
|||||||
@@ -2,20 +2,22 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useToast } from "@/app/components/ui/ToastProvider";
|
import { useToast } from "@/app/components/ui/ToastProvider";
|
||||||
|
|
||||||
export function UploadButton({ onUploaded }: { onUploaded: (url: string) => void }) {
|
export function UploadButton({ onUploaded, multiple = false }: { onUploaded: (url: string) => void; multiple?: boolean }) {
|
||||||
const { show } = useToast();
|
const { show } = useToast();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
async function onChange(e: React.ChangeEvent<HTMLInputElement>) {
|
async function onChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||||
const f = e.target.files?.[0];
|
const files = Array.from(e.target.files ?? []);
|
||||||
if (!f) return;
|
if (files.length === 0) return;
|
||||||
const fd = new FormData();
|
|
||||||
fd.append("file", f);
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const r = await fetch("/api/uploads", { method: "POST", body: fd });
|
for (const f of files) {
|
||||||
const data = await r.json();
|
const fd = new FormData();
|
||||||
if (!r.ok) throw new Error(JSON.stringify(data));
|
fd.append("file", f);
|
||||||
onUploaded(data.url);
|
const r = await fetch("/api/uploads", { method: "POST", body: fd });
|
||||||
|
const data = await r.json();
|
||||||
|
if (!r.ok) throw new Error(JSON.stringify(data));
|
||||||
|
onUploaded(data.url);
|
||||||
|
}
|
||||||
show("업로드 완료");
|
show("업로드 완료");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
show("업로드 실패");
|
show("업로드 실패");
|
||||||
@@ -26,7 +28,7 @@ export function UploadButton({ onUploaded }: { onUploaded: (url: string) => void
|
|||||||
}
|
}
|
||||||
return <label style={{ display: "inline-block" }}>
|
return <label style={{ display: "inline-block" }}>
|
||||||
<span style={{ padding: "6px 10px", border: "1px solid #ddd", borderRadius: 6, cursor: "pointer" }}>{loading ? "업로드 중..." : "이미지 업로드"}</span>
|
<span style={{ padding: "6px 10px", border: "1px solid #ddd", borderRadius: 6, cursor: "pointer" }}>{loading ? "업로드 중..." : "이미지 업로드"}</span>
|
||||||
<input type="file" accept="image/*" onChange={onChange} style={{ display: "none" }} />
|
<input type="file" accept="image/*" onChange={onChange} style={{ display: "none" }} multiple={multiple} />
|
||||||
</label>;
|
</label>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export default function NewPostPage({ searchParams }: { searchParams?: { boardId
|
|||||||
<input placeholder="boardId" value={form.boardId} onChange={(e) => setForm({ ...form, boardId: e.target.value })} />
|
<input placeholder="boardId" value={form.boardId} onChange={(e) => setForm({ ...form, boardId: e.target.value })} />
|
||||||
<input placeholder="제목" value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} />
|
<input placeholder="제목" value={form.title} onChange={(e) => setForm({ ...form, title: e.target.value })} />
|
||||||
<textarea placeholder="내용" value={form.content} onChange={(e) => setForm({ ...form, content: e.target.value })} rows={10} />
|
<textarea placeholder="내용" value={form.content} onChange={(e) => setForm({ ...form, content: e.target.value })} rows={10} />
|
||||||
<UploadButton onUploaded={(url) => setForm((f) => ({ ...f, content: `${f.content}\n` }))} />
|
<UploadButton multiple onUploaded={(url) => setForm((f) => ({ ...f, content: `${f.content}\n` }))} />
|
||||||
<button disabled={loading} onClick={submit}>{loading ? "저장 중..." : "등록"}</button>
|
<button disabled={loading} onClick={submit}>{loading ? "저장 중..." : "등록"}</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
7.7 신고→알림→블라인드 자동화 훅 o
|
7.7 신고→알림→블라인드 자동화 훅 o
|
||||||
7.8 일반 게시판 공용 폼/라우트 템플릿 생성 o
|
7.8 일반 게시판 공용 폼/라우트 템플릿 생성 o
|
||||||
7.9 일반 카테고리 설정 매핑(공지/가입인사/버그건의/이벤트/소통방/자유/무엇이든/마사지꿀팁/관리사찾아요/청와대/방문후기[승인]) o
|
7.9 일반 카테고리 설정 매핑(공지/가입인사/버그건의/이벤트/소통방/자유/무엇이든/마사지꿀팁/관리사찾아요/청와대/방문후기[승인]) o
|
||||||
7.10 제휴업소 일반(사진) 카테고리 전용 이미지 첨부/미리보기 규칙
|
7.10 제휴업소 일반(사진) 카테고리 전용 이미지 첨부/미리보기 규칙 o
|
||||||
|
|
||||||
[특수 페이지(카테고리)]
|
[특수 페이지(카테고리)]
|
||||||
8.1 출석부: 데일리 체크인/중복 방지/포인트 지급/누적 통계
|
8.1 출석부: 데일리 체크인/중복 방지/포인트 지급/누적 통계
|
||||||
|
|||||||
Reference in New Issue
Block a user