@doolehealth/service-lib 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -178,16 +178,20 @@ class ApiEndpointsService {
178
178
  //private constants: Constants,
179
179
  endpoints) {
180
180
  this.endpoints = endpoints;
181
- this.getEndpoint = (action) => this.createUrl(action, false);
182
- this.getDooleEndpoint = (action) => this.createUrl(action, true);
181
+ this.getEndpoint = (action) => this.createUrl(action);
182
+ this.getEndpointNoApi = (action) => this.createUrlNoAPI(action);
183
183
  this.getEndpointWithParameters = (action, parameters) => this.createUrlWithQueryParameters(action, parameters);
184
184
  }
185
185
  /* #region URL CREATOR */
186
186
  // URL
187
- createUrl(action, isDooleAPI = false) {
187
+ createUrl(action) {
188
188
  const urlBuilder = new UrlBuilder(this.endpoints.API_ENDPOINT, action);
189
189
  return urlBuilder.toString();
190
190
  }
191
+ createUrlNoAPI(action) {
192
+ const urlBuilder = new UrlBuilder(this.endpoints.DOOLE_ENDPOINT, action);
193
+ return urlBuilder.toString();
194
+ }
191
195
  // URL WITH QUERY PARAMS
192
196
  createUrlWithQueryParameters(action, queryStringHandler) {
193
197
  //Change EndPoind
@@ -581,13 +585,13 @@ class AuthenticationService {
581
585
  localStorage.removeItem('login_request_locked_at');
582
586
  }
583
587
  get(endpt) {
584
- const endpoint = this.api.getDooleEndpoint(endpt);
588
+ const endpoint = this.api.getEndpoint(endpt);
585
589
  return this.http.get(endpoint).pipe(map((res) => {
586
590
  return res;
587
591
  }));
588
592
  }
589
593
  post(endpt, items) {
590
- const endpoint = this.api.getDooleEndpoint(endpt);
594
+ const endpoint = this.api.getEndpoint(endpt);
591
595
  return this.http.post(endpoint, items).pipe(map((res) => {
592
596
  return res;
593
597
  }));
@@ -916,6 +920,29 @@ class DooleService {
916
920
  this.alertController = alertController;
917
921
  this.translate = translate;
918
922
  }
923
+ transformYouTubeUrl(url) {
924
+ if (!url)
925
+ return url;
926
+ // Regular expression to match various YouTube URL formats
927
+ const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
928
+ const match = url.match(regExp);
929
+ if (match && match[2].length === 11) {
930
+ const videoId = match[2];
931
+ // Use the proxy solution to avoid Error 153 in iOS Capacitor apps
932
+ return this.api.getEndpointNoApi('youtube') + '?videoId=' + videoId;
933
+ }
934
+ return url;
935
+ }
936
+ replaceYouTubeIframes(html) {
937
+ if (!html)
938
+ return html;
939
+ // Regex to find iframes with YouTube embed URLs
940
+ const iframeRegex = /<iframe[^>]*src="([^"]*youtube\.com\/embed\/([^"?#]+)[^"]*)"[^>]*><\/iframe>/gi;
941
+ return html.replace(iframeRegex, (match, fullUrl, videoId) => {
942
+ const proxyUrl = this.transformYouTubeUrl(fullUrl);
943
+ return match.replace(fullUrl, proxyUrl);
944
+ });
945
+ }
919
946
  uploadFile(image, id) {
920
947
  ////console.log("uploading ", image);
921
948
  const token = localStorage.getItem('token');
@@ -1743,8 +1770,7 @@ class DooleService {
1743
1770
  let path = `diet/${id}`;
1744
1771
  const endpoint = this.api.getEndpoint(path);
1745
1772
  let httpParams = new HttpParams()
1746
- .set('interactions', 1)
1747
- .set('tags', 1);
1773
+ .set('interactions', 1);
1748
1774
  return this.http.get(endpoint, httpParams).pipe(map((res) => {
1749
1775
  //////console.log(`[DooleService] getAPIdetailDiets(${path}) res: `, res);
1750
1776
  return res;
@@ -1753,8 +1779,7 @@ class DooleService {
1753
1779
  getAPIdetailRecipe(id) {
1754
1780
  let path = `diet/receipt/${id}`;
1755
1781
  let httpParams = new HttpParams()
1756
- .set('interactions', 1)
1757
- .set('tags', 1);
1782
+ .set('interactions', 1);
1758
1783
  const endpoint = this.api.getEndpoint(path);
1759
1784
  return this.http.get(endpoint, httpParams).pipe(map((res) => {
1760
1785
  //////console.log(`[DooleService] getAPIdetailRecipe(${path}) res: `, res);
@@ -1816,7 +1841,6 @@ class DooleService {
1816
1841
  let path = `user/new/${id}`;
1817
1842
  const endpoint = this.api.getEndpoint(path);
1818
1843
  let httpParams = new HttpParams()
1819
- .set('tags', 1)
1820
1844
  .set('interactions', 1);
1821
1845
  return this.http.get(endpoint, httpParams).pipe(map((res) => {
1822
1846
  //////console.log(`[DooleService] getAPIdetailNew(${path}) res: `, res);
@@ -1827,7 +1851,6 @@ class DooleService {
1827
1851
  let path = `advice/${id}`;
1828
1852
  const endpoint = this.api.getEndpoint(path);
1829
1853
  let httpParams = new HttpParams()
1830
- .set('tags', 1)
1831
1854
  .set('interactions', 1);
1832
1855
  return this.http.get(endpoint, httpParams).pipe(map((res) => {
1833
1856
  return res;
@@ -2453,20 +2476,14 @@ class DooleService {
2453
2476
  getAPIExerciseDetail(id, params) {
2454
2477
  let path = `user/exercise/${id}`;
2455
2478
  let httpParams = new HttpParams();
2456
- if (params?.programable_play) {
2457
- httpParams = httpParams.append('programable_play', params.programable_play);
2458
- }
2459
- if (params?.challenge_id) {
2460
- httpParams = httpParams.append('challenge_id', params.challenge_id);
2461
- }
2462
- if (params?.programable_id) {
2463
- httpParams = httpParams.append('programable_id', params.programable_id);
2464
- }
2465
- // Agregar correctamente los parámetros
2479
+ httpParams = (params?.programable_play) ? httpParams.append('programable_play', params?.programable_play) : httpParams;
2480
+ httpParams = (params?.challenge_id) ? httpParams.append('challenge_id', params?.challenge_id) : httpParams;
2481
+ httpParams = (params?.programable_id) ? httpParams.append('programable_id', params?.programable_id) : httpParams;
2482
+ // Agregar el parámetro 'interactions'
2466
2483
  httpParams = httpParams.set('interactions', '1');
2467
- httpParams = httpParams.set('tags', '1');
2468
2484
  const endpoint = this.api.getEndpoint(path);
2469
2485
  return this.http.get(endpoint, httpParams).pipe(map((res) => {
2486
+ ////console.log(`[DooleService] getAPIExercises(${path}) res: `, res);
2470
2487
  return res;
2471
2488
  }));
2472
2489
  }