'use server'; import PostReactionRequest from '@/dtos/request/forum/post/postReactionRequest'; import PostBookmarkRequest from '@/dtos/request/forum/post/postBookmarkRequest'; import PostReportRequest from '@/dtos/request/forum/post/postReportRequest'; import PostFileDownLogRequest from '@/dtos/request/forum/post/postFileDownLogRequest'; import PostCreateResponse from '@/dtos/response/forum/post/postCreateResponse'; import PostUpdateResponse from '@/dtos/response/forum/post/postUpdateResponse'; import PostResponse from '@/dtos/response/forum/post/postResponse'; import { ResultDto } from '@/dtos/response/common'; import { fetchJson } from '@/lib/utils/server'; // 게시글 등록 export async function fetchPostCreate(formData: FormData): Promise> { return await fetchJson('/api/forum/posts', { method: 'POST', headers: {'Accept': 'application/json'}, body: formData }); } // 게시글 정보 조회 export async function fetchPostData(postID: number): Promise> { const post = await fetchJson(`/api/forum/posts/${postID}`, { method: 'GET', headers: { 'Accept': 'application/json' } }); if (post.success && post.data) { // 이미지 URL 변경 post.data.content = post.data.content.replace(/]*?\bsrc=["']?(\/[^"'\s>]*)["']?/gi, (match, src) => { return match.replace(src, process.env.API_URL + src); }); } return post; } // 게시글 반응(좋아요/싫어요) 처리 export async function fetchPostReaction(params: PostReactionRequest): Promise { return await fetchJson(`/api/forum/posts/${params.postID}/reaction`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ reaction: params.reaction }) }); } // 게시글 즐겨찾기 처리 export async function fetchPostBookmark(params: PostBookmarkRequest): Promise { return await fetchJson(`/api/forum/posts/${params.postID}/bookmark`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }); } // 게시글 신고 export async function fetchReport(params: PostReportRequest): Promise { return await fetchJson(`/api/forum/posts/${params.postID}/report`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ type: params.type, reason: params.reason }) }); } // 게시글 삭제 export async function fetchPostDelete(postID: number): Promise { return await fetchJson(`/api/forum/posts/${postID}`, { method: 'DELETE', headers: { 'Accept': 'application/json' } }); } // 게시글 수정 export async function fetchPostUpdate(postID: number, formData: FormData): Promise> { return await fetchJson(`/api/forum/posts/${postID}`, { method: 'PUT', headers: { 'Accept': 'application/json', }, body: formData }); } // 파일 다운로드 기록 export async function fetchFileDownLog(params: PostFileDownLogRequest): Promise> { return await fetchJson(`/api/forum/posts/files/${params.uuid}/download`, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } }); }