| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL |
| | 4 | | { |
| | 5 | | public static class ContentServerUtils |
| | 6 | | { |
| | 7 | | [System.Serializable] |
| | 8 | | public class ScenesAPIData |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | public class Data |
| | 12 | | { |
| | 13 | | public string parcel_id; |
| | 14 | | public string root_cid; |
| | 15 | | public string scene_cid; |
| | 16 | | } |
| | 17 | |
|
| | 18 | | public Data[] data; |
| | 19 | | } |
| | 20 | |
|
| | 21 | | [System.Serializable] |
| | 22 | | public class MappingsAPIData |
| | 23 | | { |
| | 24 | | [System.Serializable] |
| | 25 | | public class Data |
| | 26 | | { |
| | 27 | | [System.Serializable] |
| | 28 | | public class Content |
| | 29 | | { |
| | 30 | | public MappingPair[] contents; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public Content content; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public Data[] data; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | [System.Serializable] |
| | 40 | | public class MappingPair |
| | 41 | | { |
| | 42 | | public string file; |
| | 43 | | public string hash; |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public enum ApiTLD |
| | 47 | | { |
| | 48 | | NONE, |
| | 49 | | TODAY, |
| | 50 | | ZONE, |
| | 51 | | ORG, |
| | 52 | | } |
| | 53 | |
|
| | 54 | | public static string GetTldString(ApiTLD tld) |
| | 55 | | { |
| | 56 | | switch (tld) |
| | 57 | | { |
| | 58 | | case ApiTLD.NONE: |
| | 59 | | break; |
| | 60 | | case ApiTLD.TODAY: |
| 0 | 61 | | return "today"; |
| | 62 | | case ApiTLD.ZONE: |
| 0 | 63 | | return "zone"; |
| | 64 | | case ApiTLD.ORG: |
| 0 | 65 | | return "org"; |
| | 66 | | } |
| | 67 | |
|
| 0 | 68 | | return "org"; |
| | 69 | | } |
| | 70 | |
|
| 0 | 71 | | public static string customBaseUrl = ""; |
| | 72 | |
|
| | 73 | | public static string GetBaseUrl(ApiTLD tld) |
| | 74 | | { |
| 0 | 75 | | if (tld != ApiTLD.NONE) |
| 0 | 76 | | return $"https://peer-lb.decentraland.{GetTldString(tld)}/lambdas/contentv2"; |
| | 77 | |
|
| 0 | 78 | | return customBaseUrl; |
| | 79 | | } |
| | 80 | |
|
| | 81 | | public static string GetScenesAPIUrl(ApiTLD env, int x1, int y1, int width, int height) |
| | 82 | | { |
| 0 | 83 | | width = Mathf.Max(0, width - 1); |
| 0 | 84 | | height = Mathf.Max(0, height - 1); |
| | 85 | |
|
| 0 | 86 | | string baseUrl = GetBaseUrl(env); |
| 0 | 87 | | string result = $"{baseUrl}/scenes?x1={x1}&x2={x1 + width}&y1={y1}&y2={y1 + height}"; |
| 0 | 88 | | Debug.Log($"Using scenes API url {result}"); |
| 0 | 89 | | return result; |
| | 90 | | } |
| | 91 | |
|
| | 92 | | public static string GetMappingsAPIUrl(ApiTLD env, string cid) |
| | 93 | | { |
| 0 | 94 | | string baseUrl = GetBaseUrl(env); |
| 0 | 95 | | string result = $"{baseUrl}/parcel_info?cids={cid}"; |
| 0 | 96 | | Debug.Log($"Using mappings url {result}"); |
| 0 | 97 | | return result; |
| | 98 | | } |
| | 99 | |
|
| | 100 | | public static string GetContentAPIUrlBase(ApiTLD env) |
| | 101 | | { |
| 0 | 102 | | string baseUrl = GetBaseUrl(env); |
| 0 | 103 | | return $"{baseUrl}/contents/"; |
| | 104 | | } |
| | 105 | | } |
| | 106 | | } |