summaryrefslogtreecommitdiff
path: root/lib/knox-api/common.ts
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-07-22 03:45:58 +0000
committerjoonhoekim <26rote@gmail.com>2025-07-22 03:45:58 +0000
commite1b1b57b6bfcd18ba4daa44230e8a915b4e93a15 (patch)
tree434ead1baf9aba787316f7cf129e7a447e9c98e7 /lib/knox-api/common.ts
parentcb34c5e1a61a20c954e12a8219d82dbdfbe50e13 (diff)
(김준회) knox 동기화 로직 개선
Diffstat (limited to 'lib/knox-api/common.ts')
-rw-r--r--lib/knox-api/common.ts43
1 files changed, 43 insertions, 0 deletions
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<KnoxConfig> => {
+ 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<Record<string, string>> => {
+ const config = await getKnoxConfig();
+ return {
+ 'Content-Type': contentType,
+ 'System-ID': config.systemId,
+ Authorization: `Bearer ${config.bearerToken}`,
+ };
+};
+
+// JSON 전용 헤더
+export const createJsonHeaders = async (): Promise<Record<string, string>> => {
+ return await createHeaders('application/json');
+};
+
+// FormData 전용 헤더 (Content-Type 자동 설정)
+export const createFormHeaders = async (): Promise<Record<string, string>> => {
+ const config = await getKnoxConfig();
+ return {
+ 'System-ID': config.systemId,
+ Authorization: `Bearer ${config.bearerToken}`,
+ };
+}; \ No newline at end of file