1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

IPFS publishing fixes, allow dropping multiple files

This commit is contained in:
Matthias Kretschmann 2019-09-09 22:23:29 +02:00
parent da357b82c2
commit e512ed4471
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 19 additions and 8 deletions

View File

@ -59,3 +59,4 @@ REACT_APP_REPORT_EMAIL="test@example.com"
# REACT_APP_SHOW_CHANNELS=true
# REACT_APP_ALLOW_PRICING=true
# REACT_APP_SHOW_REQUEST_TOKENS_BUTTON=true
# REACT_APP_IPFS_GATEWAY_URI="https://gateway.ipfs.io"

View File

@ -35,3 +35,6 @@ export const allowPricing =
process.env.REACT_APP_ALLOW_PRICING === 'true' || false
export const showRequestTokens =
process.env.REACT_APP_SHOW_REQUEST_TOKENS_BUTTON === 'true' || false
// https://ipfs.github.io/public-gateway-checker/
export const ipfsGatewayUri =
process.env.REACT_APP_IPFS_GATEWAY_URI || 'https://gateway.ipfs.io'

View File

@ -24,7 +24,7 @@ export default function useIpfsApi(config: IpfsConfig) {
ipfsMessage = 'Checking IPFS gateway...'
try {
const message = 'Connected to IPFS gateway'
const message = `Connected to ${config.host}`
console.time(message)
ipfs = await ipfsClient(config)
console.timeEnd(message)

View File

@ -6,6 +6,7 @@ import Label from '../../../../components/atoms/Form/Label'
import Spinner from '../../../../components/atoms/Spinner'
import Dropzone from '../../../../components/molecules/Dropzone'
import { formatBytes, pingUrl } from './utils'
import { ipfsGatewayUri } from '../../../../config'
import styles from './index.module.scss'
const config = {
@ -26,10 +27,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
const [loading, setLoading] = useState(false)
const [message, setMessage] = useState('')
async function saveToIpfs(
data: File | Buffer | ReadableStream,
size: number
) {
async function saveToIpfs(data: Buffer, size: number) {
const totalSize = formatBytes(size, 0)
setLoading(true)
@ -52,9 +50,8 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
// Ping gateway url to make it globally available,
// but store native url in DDO.
// https://ipfs.github.io/public-gateway-checker/
const urlGateway = `${ipfsGatewayUri}/ipfs/${cid}`
const url = `ipfs://${cid}`
const urlGateway = `https://ipfs.infura.io/ipfs/${cid}`
setMessage('Checking IPFS gateway URL')
await pingUrl(urlGateway)
@ -68,7 +65,15 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
}
function handleOnDrop(files: File[]) {
files.forEach((file: File) => saveToIpfs(file, file.size))
files.forEach((file: File) => {
const reader: any = new FileReader()
reader.readAsArrayBuffer(file)
reader.onloadend = () => {
const buffer: any = Buffer.from(reader.result)
saveToIpfs(buffer, file.size)
}
})
}
return (

View File

@ -128,6 +128,8 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
isFormShown: false,
isIpfsFormShown: false
})
this.forceUpdate()
}
private removeFile = (index: number) => {