summaryrefslogtreecommitdiff
path: root/lib/knox-api/common.ts
diff options
context:
space:
mode:
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