summaryrefslogtreecommitdiff
path: root/lib/information
diff options
context:
space:
mode:
Diffstat (limited to 'lib/information')
-rw-r--r--lib/information/service.ts74
-rw-r--r--lib/information/table/update-information-dialog.tsx4
2 files changed, 43 insertions, 35 deletions
diff --git a/lib/information/service.ts b/lib/information/service.ts
index 2826c0e9..2d3ad079 100644
--- a/lib/information/service.ts
+++ b/lib/information/service.ts
@@ -1,8 +1,6 @@
"use server"
-import { revalidateTag } from "next/cache"
import { getErrorMessage } from "@/lib/handle-error"
-import { unstable_cache } from "@/lib/unstable-cache"
import { desc, or, eq } from "drizzle-orm"
import db from "@/db/db"
import { pageInformation, menuAssignments } from "@/db/schema"
@@ -45,22 +43,29 @@ export async function getInformationLists() {
// 페이지별 인포메이션 조회 (첨부파일 포함)
export async function getPageInformation(pagePath: string) {
try {
- return await getInformationByPagePathWithAttachments(pagePath)
+ console.log('🔍 Information Service - 조회 시작:', { pagePath })
+ const result = await getInformationByPagePathWithAttachments(pagePath)
+ console.log('📊 Information Service - 조회 결과:', {
+ pagePath,
+ found: !!result,
+ resultData: result ? {
+ id: result.id,
+ pagePath: result.pagePath,
+ pageName: result.pageName,
+ attachmentsCount: result.attachments?.length || 0
+ } : null
+ })
+ return result
} catch (error) {
console.error(`Failed to get information for page ${pagePath}:`, error)
return null
}
}
-// 캐시된 페이지별 인포메이션 조회
-export const getCachedPageInformation = unstable_cache(
- async (pagePath: string) => getPageInformation(pagePath),
- ["page-information"],
- {
- tags: ["page-information"],
- revalidate: 3600, // 1시간 캐시
- }
-)
+// 페이지별 인포메이션 조회 (직접 호출용)
+export async function getPageInformationDirect(pagePath: string) {
+ return await getPageInformation(pagePath)
+}
// 인포메이션 수정 (내용과 첨부파일만)
export async function updateInformationData(input: UpdateInformationSchema) {
@@ -83,9 +88,7 @@ export async function updateInformationData(input: UpdateInformationSchema) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
- revalidateTag("information-edit-permission") // 편집 권한 캐시 무효화
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -113,13 +116,18 @@ export async function getInformationDetail(id: number) {
// 인포메이션 편집 권한 확인
export async function checkInformationEditPermission(pagePath: string, userId: string): Promise<boolean> {
try {
+ // pagePath 정규화 (앞의 / 제거)
+ const normalizedPagePath = pagePath.startsWith('/') ? pagePath.slice(1) : pagePath
+
// pagePath를 menuPath로 변환 (pagePath가 menuPath의 마지막 부분이라고 가정)
// 예: pagePath "vendor-list" -> menuPath "/evcp/vendor-list" 또는 "/partners/vendor-list"
const menuPathQueries = [
- `/evcp/${pagePath}`,
- `/partners/${pagePath}`,
- `/${pagePath}`, // 루트 경로
- pagePath // 정확한 매칭
+ `/evcp/${normalizedPagePath}`,
+ `/partners/${normalizedPagePath}`,
+ `/${normalizedPagePath}`, // 루트 경로
+ normalizedPagePath, // 정확한 매칭
+ `/${pagePath}`, // 원본 경로도 체크
+ pagePath // 원본 경로 정확한 매칭
]
// menu_assignments에서 해당 pagePath와 매칭되는 메뉴 찾기
@@ -149,15 +157,10 @@ export async function checkInformationEditPermission(pagePath: string, userId: s
}
}
-// 캐시된 권한 확인
-export const getCachedEditPermission = unstable_cache(
- async (pagePath: string, userId: string) => checkInformationEditPermission(pagePath, userId),
- ["information-edit-permission"],
- {
- tags: ["information-edit-permission"],
- revalidate: 300, // 5분 캐시
- }
-)
+// 권한 확인 (직접 호출용)
+export async function getEditPermissionDirect(pagePath: string, userId: string) {
+ return await checkInformationEditPermission(pagePath, userId)
+}
// menu_assignments 기반으로 page_information 동기화
export async function syncInformationFromMenuAssignments() {
@@ -170,9 +173,14 @@ export async function syncInformationFromMenuAssignments() {
// upsert를 사용하여 각 메뉴 항목 처리
for (const menu of menuItems) {
try {
+ // 맨 앞의 / 제거하여 pagePath 정규화
+ const normalizedPagePath = menu.menuPath.startsWith('/')
+ ? menu.menuPath.slice(1)
+ : menu.menuPath;
+
await db.insert(pageInformation)
.values({
- pagePath: menu.menuPath,
+ pagePath: normalizedPagePath,
pageName: menu.menuTitle,
informationContent: "",
isActive: true // 기본값으로 활성화
@@ -191,7 +199,7 @@ export async function syncInformationFromMenuAssignments() {
}
}
- revalidateTag("information");
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -249,8 +257,7 @@ export async function uploadInformationAttachment(formData: FormData) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
+ // 캐시 무효화 제거됨
return {
success: true,
@@ -288,8 +295,7 @@ export async function deleteInformationAttachmentAction(attachmentId: number) {
}
}
- revalidateTag("page-information")
- revalidateTag("information-lists")
+ // 캐시 무효화 제거됨
return {
success: true,
diff --git a/lib/information/table/update-information-dialog.tsx b/lib/information/table/update-information-dialog.tsx
index a02b6eb1..370eb763 100644
--- a/lib/information/table/update-information-dialog.tsx
+++ b/lib/information/table/update-information-dialog.tsx
@@ -44,7 +44,7 @@ import {
downloadInformationAttachment
} from "@/lib/information/service"
import type { PageInformation, InformationAttachment } from "@/db/schema/information"
-import { downloadFile } from "@/lib/file-download"
+// downloadFile은 동적으로 import
import prettyBytes from "pretty-bytes"
const MAX_FILE_SIZE = 50 * 1024 * 1024 // 50MB
@@ -126,6 +126,8 @@ export function UpdateInformationDialog({
try {
const result = await downloadInformationAttachment(attachment.id)
if (result.success && result.data) {
+ // 동적으로 downloadFile 함수 import
+ const { downloadFile } = await import('@/lib/file-download')
await downloadFile(result.data.filePath, result.data.fileName)
toast.success("파일 다운로드가 시작되었습니다.")
} else {