HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/services/api.service.ts
import { Injectable, Inject, forwardRef } from "@angular/core";
import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http";
import { CityService } from "./city.service";
import { StorageService } from "./storage.service";

@Injectable({
  providedIn: "root",
})
export class ApiService {
  constructor(
    public http: HttpClient,
    @Inject(forwardRef(() => CityService)) public cityService: CityService,
    private storageService: StorageService
  ) {
  }

  public getUrl() {
    return this.cityService._urlAdmin;
  }

  async get(endpoint: string, token?: any, params?: any, reqOpts?: any) {
    const myToken = await this.getAccessToken();
    try {
        token = myToken || token;
    } catch (error) {
        console.log("unauthorized", endpoint);
    }

    let headers = new HttpHeaders({
      Authorization: "Bearer " + token,
    });

    if (!reqOpts) {
      reqOpts = {
        params: new HttpParams(),
        headers: headers,
      };
    }

    // Support easy query params for GET requests
    if (params) {
      reqOpts.params = new HttpParams();
      for (let k in params) {
        reqOpts.params = reqOpts.params.set(k, params[k]);
      }
    }

    return this.http.get(await this.cityService.getApiUrl() + "/" + endpoint, reqOpts);
  }

  async getFree(endpoint: string, params?: any, reqOpts?: any) {
    if (!reqOpts) {
      reqOpts = {
        params: new HttpParams(),
      };
    }

    // Support easy query params for GET requests
    if (params) {
      reqOpts.params = new HttpParams();
      for (let k in params) {
        reqOpts.params = reqOpts.params.set(k, params[k]);
      }
    }

    return this.http.get(await this.cityService.getApiUrl() + "/" + endpoint, reqOpts);
  }

  async postFile(endpoint: string, formData: FormData, token: any, reqOpts?: any) {
    let headers = new HttpHeaders({
      Authorization: "Bearer " + token,
    });

    return this.http.post(await this.cityService.getApiUrl() + "/" + endpoint, formData, { headers });
  }

  async post(endpoint: string, body: any, token?: any) {
    const myToken = await this.getAccessToken();
    try {
        token = myToken || token;
    } catch (error) {
        console.log("unauthorized", endpoint);
    }

    let headers = new HttpHeaders({
      Authorization: "Bearer " + token,
    });

    return this.http.post(await this.cityService.getApiUrl() + "/" + endpoint, body, { headers });
  }

  postFree(endpoint: string, body: any, reqOpts?: any) {
    return this.http.post(this.cityService._urlApi + "/" + endpoint, body, reqOpts);
  }

  put(endpoint: string, body: any, token: any, reqOpts?: any) {
    let headers = new HttpHeaders({
      Authorization: "Bearer " + token,
    });

    return this.http.put(this.cityService._urlApi + "/" + endpoint, body, { headers });
  }

  putFree(endpoint: string, body: any, reqOpts?: any) {
    return this.http.put(this.cityService._urlApi + "/" + endpoint, body, reqOpts);
  }

  delete(endpoint: string, token, reqOpts?: any) {
    let headers = new HttpHeaders({
      Authorization: "Bearer " + token,
    });

    if (!reqOpts) {
      reqOpts = {
        params: new HttpParams(),
        headers: headers,
      };
    }

    return this.http.delete(this.cityService._urlApi + "/" + endpoint, reqOpts);
  }

  patch(endpoint: string, body: any, reqOpts?: any) {
    return this.http.patch(this.cityService._urlApi + "/" + endpoint, body, reqOpts);
  }

  public getAccessToken(): Promise<string> {
    return new Promise((resolve, reject) => {
      this.storageService.get("token").then((token) => {
        resolve(token ? token.access_token : '');
      });
    });
  }
}