BKK-WeSpace / tree-population

How many trees in Bangkok?
https://bkk-wespace.netlify.app
26 stars 18 forks source link

use network handler. #138

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

https://api.github.com/BKK-WeSpace/tree-population/blob/b35213d1420edaa76d0d4902899c7452d25a0e3a/src/data/services/VallarisService.ts#L67


    return data;
  }

  public static async upload(
    filePath: string
  ): Promise<FetchResult<UploadImageResponse>> {
    const formdata = new FormData();
    formdata.append("files", filePath, "[PROXY]");

    const response = await this._networkHandler.handle<UploadImageResponse>({
      method: "POST",
      body: formdata,
      redirect: "follow",
      path: "/utilities/1.0/files",
    });

    return response;
  }

  public static async downloadTreeImage(tree: Tree): Promise<Blob> {
    if (!tree.properties?.imgId) {
      throw new Error("The image id of this tree is null");
    }

    // TODO use network handler.
    const response = await fetch(
      this._networkHandler.baseUrl +
        "/utilities/1.0/files/" +
        tree.properties.imgId +
        "/download"
    );
    const result = await response.blob();

    return result;
  }

  /**
   * Returns a pre-configured Libre map style
   *