This commit is contained in:
@@ -37,6 +37,37 @@ function generateNickname(i) {
|
|||||||
return `user${String(i + 1).padStart(3, "0")}${suffix}`;
|
return `user${String(i + 1).padStart(3, "0")}${suffix}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 랜덤 제목/문장/이미지 도우미
|
||||||
|
const TITLE_FRAGMENTS = [
|
||||||
|
"오늘의 이슈", "핫 토픽", "소소한 일상", "정보 공유", "꿀팁 모음",
|
||||||
|
"개발 노트", "버그 리포트", "아이디어 제안", "질문 있습니다", "토론해요",
|
||||||
|
];
|
||||||
|
const SENTENCES = [
|
||||||
|
"안녕하세요, 간단히 공유 드립니다.",
|
||||||
|
"도움이 되셨다면 댓글로 알려주세요.",
|
||||||
|
"의견이나 질문은 언제든 환영입니다.",
|
||||||
|
"테스트로 작성된 시드 데이터입니다.",
|
||||||
|
"참고용 스크린샷을 함께 첨부합니다.",
|
||||||
|
"관련 경험 있으시면 팁 부탁드려요.",
|
||||||
|
"문서화가 필요해 간단히 정리했습니다.",
|
||||||
|
"링크와 자료를 함께 첨부합니다.",
|
||||||
|
"개선 제안은 자유롭게 남겨주세요.",
|
||||||
|
"읽어주셔서 감사합니다.",
|
||||||
|
];
|
||||||
|
function randomTitle(boardName, index) {
|
||||||
|
const a = TITLE_FRAGMENTS[randomInt(0, TITLE_FRAGMENTS.length - 1)];
|
||||||
|
const b = TITLE_FRAGMENTS[randomInt(0, TITLE_FRAGMENTS.length - 1)];
|
||||||
|
return `${boardName} ${a} · ${b} #${index + 1}`;
|
||||||
|
}
|
||||||
|
function randomSentence() {
|
||||||
|
return SENTENCES[randomInt(0, SENTENCES.length - 1)];
|
||||||
|
}
|
||||||
|
function randomImageUrl(seedKey, w = 800, h = 450) {
|
||||||
|
// 외부 랜덤 이미지. 네트워크가 제한되면 /sample.jpg로 대체 가능
|
||||||
|
const seed = encodeURIComponent(String(seedKey));
|
||||||
|
return `https://picsum.photos/seed/${seed}/${w}/${h}`;
|
||||||
|
}
|
||||||
|
|
||||||
async function createRandomUsers(count = 100) {
|
async function createRandomUsers(count = 100) {
|
||||||
const roleUser = await prisma.role.findUnique({ where: { name: "user" } });
|
const roleUser = await prisma.role.findUnique({ where: { name: "user" } });
|
||||||
// 사용되지 않은 전화번호를 찾는 보조 함수
|
// 사용되지 않은 전화번호를 찾는 보조 함수
|
||||||
@@ -340,11 +371,16 @@ async function createPostsForAllBoards(boards, countPerBoard = 100, admin) {
|
|||||||
const authorId = ["notice", "bug-report"].includes(board.slug)
|
const authorId = ["notice", "bug-report"].includes(board.slug)
|
||||||
? admin.userId
|
? admin.userId
|
||||||
: userIds[randomInt(0, userIds.length - 1)];
|
: userIds[randomInt(0, userIds.length - 1)];
|
||||||
|
const title = randomTitle(board.name, i);
|
||||||
|
const img = randomImageUrl(`${board.slug}-${i}`);
|
||||||
|
const p1 = randomSentence();
|
||||||
|
const p2 = randomSentence();
|
||||||
|
const p3 = randomSentence();
|
||||||
data.push({
|
data.push({
|
||||||
boardId: board.id,
|
boardId: board.id,
|
||||||
authorId,
|
authorId,
|
||||||
title: `${board.name} 샘플 글 ${i + 1}`,
|
title,
|
||||||
content: `이 게시판(${board.slug})의 자동 시드 게시물 #${i + 1} 입니다.\n\n테스트용 내용입니다.`,
|
content: `<p>${p1}</p>\n<figure><img src="${img}" alt="seed image" /></figure>\n<p>${p2}</p>\n<p>${p3}</p>`,
|
||||||
status: "published",
|
status: "published",
|
||||||
isAnonymous: board.allowAnonymousPost ? Math.random() < 0.3 : false,
|
isAnonymous: board.allowAnonymousPost ? Math.random() < 0.3 : false,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user