kleros/kleros-v2

View on GitHub
web/src/utils/getIpfsUrl.ts

Summary

Maintainability
A
3 hrs
Test Coverage
import { IPFS_GATEWAY } from "consts/index";

export const getIpfsUrl = (url: string) => {
  const formatedIPFSPath = getFormattedPath(url);
  return `${IPFS_GATEWAY}${formatedIPFSPath}`;
};

export const getFormattedPath = (url: string) => {
  if (url.startsWith("/ipfs/")) return url;
  else if (url.startsWith("ipfs/")) return "/" + url;
  else if (url.startsWith("ipfs://")) return url.replace("ipfs://", "/ipfs/");
  return url;
};