blob: 5b13fc0a38cc1865a3526d79e83aa7093523fddb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
"use server"
// Knox API 공통 설정 및 유틸리티
// 기본 설정 타입
export interface KnoxConfig {
baseUrl: string;
systemId: string;
apInfId?: 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; charset=utf-8');
};
// FormData 전용 헤더 (Content-Type 자동 설정)
export const createFormHeaders = async (): Promise<Record<string, string>> => {
const config = await getKnoxConfig();
return {
'System-ID': config.systemId,
Authorization: `Bearer ${config.bearerToken}`,
'Accept': 'application/json; charset=utf-8',
'Accept-Charset': 'utf-8',
};
};
|