post.ts 769 B

123456789101112131415161718192021222324252627
  1. 'use server';
  2. import {
  3. PostResponse
  4. } from '@/types/response/forum/post';
  5. import { ResultDto } from '@/types/response/common';
  6. import { fetchJson } from '@/lib/utils/server';
  7. // 게시글 정보 조회
  8. export async function fetchPostData(postID: number): Promise<ResultDto<PostResponse>> {
  9. const post = await fetchJson<PostResponse>(`/api/forum/posts/${postID}`, {
  10. method: 'GET',
  11. headers: {
  12. 'Accept': 'application/json'
  13. }
  14. });
  15. if (post.success && post.data) {
  16. // 이미지 URL 변경
  17. post.data.content = post.data.content.replace(/<img\b[^>]*?\bsrc=["']?(\/[^"'\s>]*)["']?/gi, (match, src) => {
  18. return match.replace(src, process.env.API_URL + src);
  19. });
  20. }
  21. return post;
  22. }