File size: 1,851 Bytes
e097ca3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { RegionInfo } from "@/api/controllers/core.ts";
import { BASE_URL_DREAMINA_US, BASE_URL_DREAMINA_HK, BASE_URL_IMAGEX_US, BASE_URL_IMAGEX_HK } from "@/api/consts/dreamina.ts";

/**
 * 区域配置工具类
 * 统一管理不同区域的配置信息
 */
export class RegionUtils {
  /**
   * 获取ServiceId
   */
  static getServiceId(regionInfo: RegionInfo, providedServiceId?: string): string {
    if (providedServiceId) {
      return providedServiceId;
    }

    // US/HK/JP/SG 使用相同的 service_id
    if (regionInfo.isUS || regionInfo.isHK || regionInfo.isJP || regionInfo.isSG) {
      return "wopfjsm1ax";
    }

    // CN 使用默认的 service_id
    return "tb4s082cfz";
  }

  /**
   * 获取ImageX URL
   */
  static getImageXUrl(regionInfo: RegionInfo): string {
    if (regionInfo.isUS) {
      return BASE_URL_IMAGEX_US;
    }

    if (regionInfo.isHK || regionInfo.isJP || regionInfo.isSG) {
      return BASE_URL_IMAGEX_HK;
    }

    return 'https://imagex.bytedanceapi.com';
  }

  /**
   * 获取Origin
   */
  static getOrigin(regionInfo: RegionInfo): string {
    if (regionInfo.isUS) {
      return new URL(BASE_URL_DREAMINA_US).origin;
    }

    if (regionInfo.isHK || regionInfo.isJP || regionInfo.isSG) {
      return new URL(BASE_URL_DREAMINA_HK).origin;
    }

    return 'https://jimeng.jianying.com';
  }

  /**
   * 获取AWS区域
   */
  static getAWSRegion(regionInfo: RegionInfo): string {
    if (regionInfo.isUS) {
      return 'us-east-1';
    }

    if (regionInfo.isHK || regionInfo.isJP || regionInfo.isSG) {
      return 'ap-southeast-1';
    }

    return 'cn-north-1';
  }

  /**
   * 获取Referer路径
   */
  static getRefererPath(regionInfo: RegionInfo, path: string = '/ai-tool/generate'): string {
    const origin = this.getOrigin(regionInfo);
    return `${origin}${path}`;
  }
}