Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
1 result

kubo.ts

Blame
  • kubo.ts 882 B
    import { create } from 'kubo-rpc-client'
    import type { IPFSHTTPClient } from 'kubo-rpc-client'
    import { CID } from 'multiformats'
    
    // env
    // TODO clean way to declare KUBO_RPC for Vue App
    // var process : NodeJS.Process | undefined = typeof(process) == "undefined" ? undefined : process
    const KUBO_RPC = process?.env.KUBO_RPC || 'http://127.0.0.1:5001'
    const KUBO_GATEWAY = process?.env.KUBO_GATEWAY || 'http://127.0.0.1:8080'
    
    // create a RPC client
    export const kubo: IPFSHTTPClient = create({ url: new URL(KUBO_RPC) })
    
    // explorer resources
    const EXPLORER_CID = 'bafybeidf7cpkwsjkq6xs3r6fbbxghbugilx3jtezbza7gua3k5wjixpmba'
    export const EXPLORER_URL = KUBO_RPC + '/ipfs/' + EXPLORER_CID + '/#'
    export function exploreUrl(cid: CID): string {
      return EXPLORER_URL + '/explore/ipfs/' + cid
    }
    export function gatewayUrl(cid: CID): string {
      return KUBO_GATEWAY + '/ipfs/' + cid
    }