1#![allow(missing_docs)]
4
5use std::env::VarError;
6
7pub const JIG_PLAYER_SESSION_VALID_DURATION_SECS: u32 = 60 * 60 * 24 * 365;
9
10pub const JIG_PLAYER_SESSION_CODE_MAX: i32 = 999999;
13
14pub const MIN_LIST_WORDS: usize = 2;
16
17pub const MAX_LIST_WORDS: usize = 14;
19
20const LOCALHOST: &str = "localhost";
21
22#[derive(Debug, PartialEq, Eq, Copy, Clone)]
23pub enum RemoteTarget {
24 Local,
25 Sandbox,
26 Release,
27}
28
29cfg_if::cfg_if! {
30 if #[cfg(feature = "wasm")] {
31 use wasm_bindgen::prelude::*;
32
33 #[wasm_bindgen(inline_js = "export function process_env_var(key) { const value = process.env[key]; return value == undefined ? '' : value; }")]
34 extern "C" {
35 #[wasm_bindgen(catch)]
36 fn process_env_var(key:&str) -> Result<String, JsValue>;
37 }
38
39 pub fn env_var(key: &str) -> Result<String, VarError> {
40 process_env_var(key)
41 .map_err(|_| {
42 VarError::NotPresent
43 })
44 .and_then(|var| if var.is_empty() { Err(VarError::NotPresent) } else { Ok(var) })
45 }
46 } else {
47 pub fn env_var(key: &str) -> Result<String, VarError> {
48 std::env::var(key)
49 }
50 }
51}
52
53impl RemoteTarget {
54 pub const fn s3_endpoint(&self) -> Option<&'static str> {
55 match self {
56 Self::Local => None,
57 Self::Sandbox | Self::Release => Some("https://storage.googleapis.com"),
58 }
59 }
60
61 pub const fn s3_processing_bucket(&self) -> Option<&'static str> {
62 match self {
63 Self::Local => None,
64 Self::Sandbox => Some("ji-cloud-sandbox-processing-eu-001"),
65 Self::Release => Some("ji-cloud-processing-eu-001"),
66 }
67 }
68
69 pub const fn s3_bucket(&self) -> Option<&'static str> {
70 match self {
71 Self::Local => None,
72 Self::Sandbox => Some("ji-cloud-sandbox-uploads-origin-eu-001"),
73 Self::Release => Some("ji-cloud-uploads-origin-eu-001"),
74 }
75 }
76
77 pub const fn google_credentials_env_name(&self) -> &'static str {
78 match self {
79 Self::Local => "GOOGLE_APPLICATION_CREDENTIALS_DEV_SANDBOX",
80 Self::Sandbox => "GOOGLE_APPLICATION_CREDENTIALS_DEV_SANDBOX",
81 Self::Release => "GOOGLE_APPLICATION_CREDENTIALS_DEV_RELEASE",
82 }
83 }
84
85 pub const fn google_eventarc_media_uploaded_topic(&self) -> Option<&'static str> {
86 match self {
87 Self::Local => None,
88 Self::Sandbox => Some("eventarc-global-trigger-media-uploaded-sandbox-959"),
89 Self::Release => Some("eventarc-global-trigger-media-uploaded-197"),
90 }
91 }
92
93 pub const fn google_eventarc_media_processed_topic(&self) -> Option<&'static str> {
94 match self {
95 Self::Local => None,
96 Self::Sandbox => Some("media-processed-sandbox"),
97 Self::Release => Some("media-processed"),
98 }
99 }
100
101 pub fn media_watch_assigned_url(&self) -> Option<&'static str> {
102 match self {
103 Self::Local => None,
104 Self::Sandbox => {
105 Some("https://ji-cloud-api-media-watch-sandbox-wlv5av7voq-ew.a.run.app")
106 }
107 Self::Release => Some("https://ji-cloud-api-media-watch-zkhkelxlzq-ew.a.run.app"),
108 }
109 }
110
111 pub fn api_assigned_url(&self) -> String {
112 match self {
113 Self::Local => env_var("LOCAL_API_URL").unwrap_or(format!("http://{LOCALHOST}:8080")),
114 Self::Sandbox => "https://ji-cloud-api-sandbox-wlv5av7voq-ew.a.run.app".to_string(),
115 Self::Release => "https://ji-cloud-api-zkhkelxlzq-ew.a.run.app".to_string(),
116 }
117 }
118
119 pub fn api_url(&self) -> String {
120 match self {
121 Self::Local => env_var("LOCAL_API_URL").unwrap_or(format!("http://{LOCALHOST}:8080")),
122 Self::Sandbox => "https://api.sandbox.jigzi.org".to_string(),
123 Self::Release => "https://api.jigzi.org".to_string(),
124 }
125 }
126
127 pub fn uploads_url(&self) -> String {
128 match self {
129 Self::Local => env_var("LOCAL_UPLOADS_URL")
130 .unwrap_or(format!("http://{LOCALHOST}:9000/test-bucket")),
131 Self::Sandbox => "https://uploads.sandbox.jigzi.org".to_string(),
132 Self::Release => "https://uploads.jigzi.org".to_string(),
133 }
134 }
135
136 pub fn media_url(&self) -> String {
137 match self {
138 Self::Local => env_var("LOCAL_MEDIA_URL").unwrap_or(format!("http://{LOCALHOST}:4102")),
139 Self::Sandbox | Self::Release => "https://media.jigzi.org".to_string(),
140 }
141 }
142
143 pub fn legacy_url(&self) -> String {
144 match self {
145 Self::Local => {
146 env_var("LOCAL_LEGACY_URL").unwrap_or(format!("http://{LOCALHOST}:4106"))
147 }
149 Self::Sandbox | Self::Release => "https://legacy.jigzi.org".to_string(),
150 }
151 }
152
153 pub fn pages_url(&self) -> String {
154 match self {
155 Self::Local => {
156 env_var("LOCAL_FRONTEND_URL").unwrap_or(format!("http://{LOCALHOST}:4104"))
157 }
158 Self::Sandbox => "https://sandbox.jigzi.org".to_string(),
159 Self::Release => "https://jigzi.org".to_string(),
160 }
161 }
162 pub fn pages_url_iframe(&self) -> String {
163 match self {
164 Self::Local => {
165 env_var("LOCAL_PAGES_URL_IFRAME").unwrap_or(format!("http://{LOCALHOST}:4104"))
166 }
167 Self::Sandbox => "https://sandbox.jigzi.org".to_string(),
168 Self::Release => "https://jigzi.org".to_string(),
169 }
170 }
171
172 pub fn frontend_url(&self) -> String {
173 match self {
174 Self::Local => {
175 env_var("LOCAL_FRONTEND_URL").unwrap_or(format!("http://{LOCALHOST}:4104"))
176 }
177 Self::Sandbox => "https://frontend.sandbox.jigzi.org".to_string(),
178 Self::Release => "https://frontend.jigzi.org".to_string(),
179 }
180 }
181
182 pub fn spa_url(&self, app: &str, path: &str) -> String {
183 format!("{}/{}/{}", self.frontend_url(), app, path)
184 }
185
186 pub fn spa_iframe(&self, route_path: &str) -> String {
188 format!("{}{}", self.pages_url_iframe(), route_path)
189 }
190
191 pub fn static_url(&self, path: &str) -> String {
192 format!("{}/static/{}", self.frontend_url(), path)
193 }
194
195 pub const fn host(&self) -> Option<&'static str> {
196 None
197 }
198
199 pub fn media_ui_url(&self) -> String {
200 format!("{}/ui", self.media_url())
201 }
202
203 pub fn media_audio_url(&self) -> String {
204 format!("{}/audio", self.media_url())
205 }
206
207 pub fn replace_media_ui<S: AsRef<str>>(&self, s: S) -> String {
208 s.as_ref()
209 .replace("%MEDIA_UI%", &format!("{}/ui", self.media_url()))
210 }
211
212 pub fn google_maps_url(&self) -> &'static str {
213 match self {
214 Self::Local
216 | Self::Sandbox => "https://maps.googleapis.com/maps/api/js?key=AIzaSyCtU4taX_GG36bXfZr98HSwZTBNYo9HS1I&libraries=places",
217 Self::Release => "https://maps.googleapis.com/maps/api/js?key=AIzaSyCU1HygSZgK4L3qPdRmrV-dTnS1GBBiqyE&libraries=places"
218 }
219 }
220
221 pub fn jigzi_info_email(&self) -> &'static str {
222 match self {
223 Self::Local | Self::Sandbox => "JiTestLB@gmail.com",
224 Self::Release => "info@jigzi.org",
225 }
226 }
227
228 pub fn screenshot_url(&self) -> String {
229 match self {
230 Self::Local | Self::Sandbox => {
231 format!("{}/queueScreenshotSandbox", self.cloud_functions_url())
232 }
233 Self::Release => {
234 format!("{}/queueScreenshotRelease", self.cloud_functions_url())
235 }
236 }
237 }
238
239 pub const fn cloud_functions_url(&self) -> &'static str {
240 match self {
241 Self::Local | Self::Sandbox => {
242 "https://europe-west1-ji-cloud-developer-sandbox.cloudfunctions.net"
243 }
244 Self::Release => "https://europe-west1-ji-cloud.cloudfunctions.net",
245 }
246 }
247
248 pub const fn as_str(&self) -> &'static str {
249 match self {
250 Self::Local => "local",
251 Self::Sandbox => "sandbox",
252 Self::Release => "release",
253 }
254 }
255}