mirror of
https://github.com/kremalicious/ipfs.git
synced 2024-11-21 17:27:06 +01:00
config changes
This commit is contained in:
parent
7843ab66b7
commit
4fabd65c86
@ -1,21 +1,13 @@
|
|||||||
import React, { useState, ReactElement } from 'react'
|
import React, { useState, ReactElement } from 'react'
|
||||||
import { ipfsNodeUri, ipfsGateway } from '../../site.config'
|
import { ipfsGateway } from '../../site.config'
|
||||||
import Dropzone, { FileDropzone } from './Dropzone'
|
import Dropzone, { FileDropzone } from './Dropzone'
|
||||||
import styles from './Add.module.css'
|
import styles from './Add.module.css'
|
||||||
import Loader from './Loader'
|
import Loader from './Loader'
|
||||||
import useIpfsApi from '../hooks/use-ipfs-api'
|
import useIpfsApi from '../hooks/use-ipfs-api'
|
||||||
import { FileIpfs } from '../@types/ipfs'
|
import { FileIpfs } from '../@types/ipfs'
|
||||||
|
|
||||||
const { hostname, port, protocol } = new URL(ipfsNodeUri)
|
|
||||||
|
|
||||||
const ipfsConfig = {
|
|
||||||
protocol: protocol.replace(':', ''),
|
|
||||||
host: hostname,
|
|
||||||
port: Number(port) || 443
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Add(): ReactElement {
|
export default function Add(): ReactElement {
|
||||||
const { ipfs, isIpfsReady, ipfsError, addFiles } = useIpfsApi(ipfsConfig)
|
const { ipfs, isIpfsReady, ipfsError, addFiles } = useIpfsApi()
|
||||||
const [files, setFiles] = useState<FileIpfs[]>()
|
const [files, setFiles] = useState<FileIpfs[]>()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [message] = useState()
|
const [message] = useState()
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { create, IPFSHTTPClient, Options } from 'ipfs-http-client'
|
import { create } from 'ipfs-http-client'
|
||||||
|
import type { IPFSHTTPClient } from 'ipfs-http-client'
|
||||||
import type { CIDVersion } from 'multiformats/cid'
|
import type { CIDVersion } from 'multiformats/cid'
|
||||||
|
import { ipfsNodeUri } from '../../site.config'
|
||||||
import { formatBytes } from '../utils'
|
import { formatBytes } from '../utils'
|
||||||
import { FileDropzone } from '../components/Dropzone'
|
import { FileDropzone } from '../components/Dropzone'
|
||||||
import { FileIpfs } from '../@types/ipfs'
|
import type { FileIpfs } from '../@types/ipfs'
|
||||||
|
|
||||||
export interface IpfsApiValue {
|
export interface IpfsApiValue {
|
||||||
ipfs: IPFSHTTPClient | undefined
|
ipfs: IPFSHTTPClient | undefined
|
||||||
@ -13,7 +15,15 @@ export interface IpfsApiValue {
|
|||||||
addFiles: (files: FileDropzone[]) => Promise<FileIpfs[] | undefined>
|
addFiles: (files: FileDropzone[]) => Promise<FileIpfs[] | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useIpfsApi(config: Options): IpfsApiValue {
|
const { hostname, port, protocol } = new URL(ipfsNodeUri)
|
||||||
|
|
||||||
|
const ipfsConfig = {
|
||||||
|
protocol: protocol.replace(':', ''),
|
||||||
|
host: hostname,
|
||||||
|
port: Number(port) || 443
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function useIpfsApi(): IpfsApiValue {
|
||||||
const [ipfs, setIpfs] = useState<IPFSHTTPClient>()
|
const [ipfs, setIpfs] = useState<IPFSHTTPClient>()
|
||||||
const [version, setVersion] = useState<string>()
|
const [version, setVersion] = useState<string>()
|
||||||
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
|
const [isIpfsReady, setIpfsReady] = useState(Boolean(ipfs))
|
||||||
@ -52,7 +62,7 @@ export default function useIpfsApi(config: Options): IpfsApiValue {
|
|||||||
|
|
||||||
async function initIpfs() {
|
async function initIpfs() {
|
||||||
try {
|
try {
|
||||||
const ipfs = create(config)
|
const ipfs = create(ipfsConfig)
|
||||||
setIpfs(ipfs)
|
setIpfs(ipfs)
|
||||||
const version = await ipfs.version()
|
const version = await ipfs.version()
|
||||||
setVersion(version.version)
|
setVersion(version.version)
|
||||||
@ -73,7 +83,7 @@ export default function useIpfsApi(config: Options): IpfsApiValue {
|
|||||||
setIpfsError(undefined)
|
setIpfsError(undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [config, ipfs])
|
}, [ipfs])
|
||||||
|
|
||||||
return { ipfs, version, isIpfsReady, ipfsError, addFiles }
|
return { ipfs, version, isIpfsReady, ipfsError, addFiles }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user