Skip to content

Commit

Permalink
safe env access
Browse files Browse the repository at this point in the history
  • Loading branch information
kevtechi committed Oct 29, 2024
1 parent 89f81d4 commit 6080b05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/ipfs/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
export const downloadJsonFromIpfs = async <T>(uri: string): Promise<T> => {
let url = uri;
if (!url.startsWith("http")) {
const baseUrl = Deno.env.get("IPFS_URL");
if (!baseUrl) {
throw new Error("IPFS_URL is not set");
}
import { getEnv } from "../utils/env.ts";

url = `${baseUrl}/${url}`;
export const downloadJsonFromIpfs = async <T>(uri: string): Promise<T> => {
let url = uri;
if (!url.startsWith("http")) {
const baseUrl = getEnv("IPFS_URL");
if (!baseUrl) {
throw new Error("IPFS_URL is not set");
}

const response = await fetch(url);
const json = await response.json();
url = `${baseUrl}/${url}`;
}

const response = await fetch(url);
const json = await response.json();

return json;
return json;
};
3 changes: 2 additions & 1 deletion src/profiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { hexlify, toUtf8Bytes, JsonRpcProvider, Contract } from "ethers";
import type { CommunityConfig } from "../index.ts";
import { downloadJsonFromIpfs } from "../ipfs/index.ts";
import profileContractAbi from "../abi/Profile.abi.json" with { type: "json" };
import { getEnv } from "../utils/env.ts";

export interface Profile {
account: string;
Expand Down Expand Up @@ -75,7 +76,7 @@ export const getProfileFromId = async (

const profile = await downloadJsonFromIpfs<Profile>(uri);

const baseUrl = Deno.env.get("IPFS_URL");
const baseUrl = getEnv("IPFS_URL");
if (!baseUrl) {
throw new Error("IPFS_URL is not set");
}
Expand Down

0 comments on commit 6080b05

Please sign in to comment.