File size: 878 Bytes
5f24abe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const MUSE_SPARK_BLOCKED_COUNTRIES = new Set([
  "AF",
  "BY",
  "CN",
  "CU",
  "EH",
  "ER",
  "ET",
  "HK",
  "HT",
  "IQ",
  "IR",
  "KH",
  "KP",
  "LY",
  "MM",
  "MO",
  "NI",
  "PK",
  "RU",
  "SO",
  "SY",
  "VE",
])

export function countryFromRequest(request: Request | undefined) {
  if (!request) return undefined
  const cloudflareRequest = request as Request & { cf?: { country?: string } }
  return cloudflareRequest.cf?.country ?? request.headers.get("cf-ipcountry") ?? undefined
}

export function isModelCountryRestricted(model: string, country: string | undefined) {
  return (
    [
      "muse-spark-1.3-contributor",
      "muse-spark-1.3-contributor-free",
      "muse-spark-1.2-contributor",
      "muse-spark-1.2-contributor-free",
    ].includes(model) &&
    country !== undefined &&
    MUSE_SPARK_BLOCKED_COUNTRIES.has(country.toUpperCase())
  )
}