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:
parent
da357b82c2
commit
e512ed4471
@ -59,3 +59,4 @@ REACT_APP_REPORT_EMAIL="test@example.com"
|
|||||||
# REACT_APP_SHOW_CHANNELS=true
|
# REACT_APP_SHOW_CHANNELS=true
|
||||||
# REACT_APP_ALLOW_PRICING=true
|
# REACT_APP_ALLOW_PRICING=true
|
||||||
# REACT_APP_SHOW_REQUEST_TOKENS_BUTTON=true
|
# REACT_APP_SHOW_REQUEST_TOKENS_BUTTON=true
|
||||||
|
# REACT_APP_IPFS_GATEWAY_URI="https://gateway.ipfs.io"
|
||||||
|
@ -35,3 +35,6 @@ export const allowPricing =
|
|||||||
process.env.REACT_APP_ALLOW_PRICING === 'true' || false
|
process.env.REACT_APP_ALLOW_PRICING === 'true' || false
|
||||||
export const showRequestTokens =
|
export const showRequestTokens =
|
||||||
process.env.REACT_APP_SHOW_REQUEST_TOKENS_BUTTON === 'true' || false
|
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'
|
||||||
|
@ -24,7 +24,7 @@ export default function useIpfsApi(config: IpfsConfig) {
|
|||||||
ipfsMessage = 'Checking IPFS gateway...'
|
ipfsMessage = 'Checking IPFS gateway...'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = 'Connected to IPFS gateway'
|
const message = `Connected to ${config.host}`
|
||||||
console.time(message)
|
console.time(message)
|
||||||
ipfs = await ipfsClient(config)
|
ipfs = await ipfsClient(config)
|
||||||
console.timeEnd(message)
|
console.timeEnd(message)
|
||||||
|
@ -6,6 +6,7 @@ import Label from '../../../../components/atoms/Form/Label'
|
|||||||
import Spinner from '../../../../components/atoms/Spinner'
|
import Spinner from '../../../../components/atoms/Spinner'
|
||||||
import Dropzone from '../../../../components/molecules/Dropzone'
|
import Dropzone from '../../../../components/molecules/Dropzone'
|
||||||
import { formatBytes, pingUrl } from './utils'
|
import { formatBytes, pingUrl } from './utils'
|
||||||
|
import { ipfsGatewayUri } from '../../../../config'
|
||||||
import styles from './index.module.scss'
|
import styles from './index.module.scss'
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
@ -26,10 +27,7 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [message, setMessage] = useState('')
|
const [message, setMessage] = useState('')
|
||||||
|
|
||||||
async function saveToIpfs(
|
async function saveToIpfs(data: Buffer, size: number) {
|
||||||
data: File | Buffer | ReadableStream,
|
|
||||||
size: number
|
|
||||||
) {
|
|
||||||
const totalSize = formatBytes(size, 0)
|
const totalSize = formatBytes(size, 0)
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@ -52,9 +50,8 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
|
|
||||||
// Ping gateway url to make it globally available,
|
// Ping gateway url to make it globally available,
|
||||||
// but store native url in DDO.
|
// but store native url in DDO.
|
||||||
// https://ipfs.github.io/public-gateway-checker/
|
const urlGateway = `${ipfsGatewayUri}/ipfs/${cid}`
|
||||||
const url = `ipfs://${cid}`
|
const url = `ipfs://${cid}`
|
||||||
const urlGateway = `https://ipfs.infura.io/ipfs/${cid}`
|
|
||||||
|
|
||||||
setMessage('Checking IPFS gateway URL')
|
setMessage('Checking IPFS gateway URL')
|
||||||
await pingUrl(urlGateway)
|
await pingUrl(urlGateway)
|
||||||
@ -68,7 +65,15 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleOnDrop(files: File[]) {
|
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 (
|
return (
|
||||||
|
@ -128,6 +128,8 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
|
|||||||
isFormShown: false,
|
isFormShown: false,
|
||||||
isIpfsFormShown: false
|
isIpfsFormShown: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.forceUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeFile = (index: number) => {
|
private removeFile = (index: number) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user