From e1b1b57b6bfcd18ba4daa44230e8a915b4e93a15 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 22 Jul 2025 03:45:58 +0000 Subject: (김준회) knox 동기화 로직 개선 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/knox-api/common.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/knox-api/common.ts (limited to 'lib/knox-api/common.ts') diff --git a/lib/knox-api/common.ts b/lib/knox-api/common.ts new file mode 100644 index 00000000..4c037e56 --- /dev/null +++ b/lib/knox-api/common.ts @@ -0,0 +1,43 @@ +"use server" + +// Knox API 공통 설정 및 유틸리티 + +// 기본 설정 타입 +export interface KnoxConfig { + baseUrl: string; + systemId: string; + bearerToken: string; +} + +// 설정 가져오기 (환경변수 또는 설정에서) +export const getKnoxConfig = async (): Promise => { + return { + baseUrl: process.env.KNOX_API_BASE_URL || 'https://openapi.samsung.net', + systemId: process.env.KNOX_SYSTEM_ID || 'KCD60REST00046', + bearerToken: process.env.KNOX_API_BEARER || '', + }; +}; + +// 공통 헤더 생성 +export const createHeaders = async (contentType: string = 'application/json'): Promise> => { + const config = await getKnoxConfig(); + return { + 'Content-Type': contentType, + 'System-ID': config.systemId, + Authorization: `Bearer ${config.bearerToken}`, + }; +}; + +// JSON 전용 헤더 +export const createJsonHeaders = async (): Promise> => { + return await createHeaders('application/json'); +}; + +// FormData 전용 헤더 (Content-Type 자동 설정) +export const createFormHeaders = async (): Promise> => { + const config = await getKnoxConfig(); + return { + 'System-ID': config.systemId, + Authorization: `Bearer ${config.bearerToken}`, + }; +}; \ No newline at end of file -- cgit v1.2.3