summaryrefslogtreecommitdiff
path: root/lib/spread-js/license-utils.ts
blob: 1f586c50d7cd52d01e616aea8d891b8a7eb0084c (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * SpreadJS 라이선스 관리 유틸리티
 * 도메인에 따라 적절한 라이선스 키를 반환합니다.
 */

/**
 * 현재 도메인을 기반으로 적절한 SpreadJS 라이선스 키를 반환합니다.
 * 
 * @returns 도메인에 맞는 라이선스 키 또는 null
 */
export function getSpreadJSLicenseKey(): string | null {
  // 서버 사이드에서는 라이선스를 설정하지 않음
  if (typeof window === 'undefined') {
    return null;
  }

  const hostname = window.location.hostname;
  
  // partners.sevcp.com 도메인 (케이스1)
  if (hostname === 'partners.sevcp.com') {
    return process.env.NEXT_PUBLIC_SPREAD_LICENSE || null;
  }
  
  // sevcp.com 도메인 (케이스2)  
  if (hostname === 'sevcp.com') {
    return process.env.NEXT_PUBLIC_SPREAD_LICENSE_SEVCP || process.env.NEXT_PUBLIC_SPREAD_LICENSE || null;
  }
  
  // 개발 환경 (localhost)
  if (hostname === 'localhost' || hostname === '127.0.0.1') {
    // 개발 환경에서는 기본 라이선스 사용
    return process.env.NEXT_PUBLIC_SPREAD_LICENSE || null;
  }
  
  // 기타 도메인의 경우 기본 라이선스 사용
  return process.env.NEXT_PUBLIC_SPREAD_LICENSE || null;
}

/**
 * SpreadJS Designer 라이선스 키를 반환합니다.
 * Designer 라이선스는 도메인 구분 없이 항상 동일한 라이선스를 사용합니다.
 * 
 * @returns Designer 라이선스 키 또는 null
 */
export function getSpreadJSDesignerLicenseKey(): string | null {
  // 서버 사이드에서는 라이선스를 설정하지 않음
  if (typeof window === 'undefined') {
    return null;
  }

  // Designer 라이선스는 도메인 구분 없이 항상 동일한 라이선스 사용
  return process.env.NEXT_PUBLIC_DESIGNER_LICENSE || null;
}

/**
 * SpreadJS 라이선스를 설정합니다.
 * GC 객체가 로드된 후에 호출해야 합니다.
 * 
 * @param GC - SpreadJS GC 객체
 */
export function setupSpreadJSLicense(GC: any): void {
  if (typeof window === 'undefined') {
    return;
  }

  const spreadLicense = getSpreadJSLicenseKey();
  const designerLicense = getSpreadJSDesignerLicenseKey();

  // SpreadSheets 라이선스 설정
  if (spreadLicense && GC?.Spread?.Sheets) {
    GC.Spread.Sheets.LicenseKey = spreadLicense;
    
    // ExcelIO 라이선스 설정 (있는 경우)
    if (typeof (window as any).ExcelIO !== 'undefined') {
      (window as any).ExcelIO.LicenseKey = spreadLicense;
    }
  }

  // Designer 라이선스 설정
  if (designerLicense && GC?.Spread?.Sheets?.Designer) {
    GC.Spread.Sheets.Designer.LicenseKey = designerLicense;
  }
}