1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
This commit is contained in:
Matthias Kretschmann 2019-09-09 15:13:44 +02:00
parent a2a6720fd8
commit 839140d906
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 27 additions and 27 deletions

View File

@ -4,7 +4,7 @@
margin-top: $spacer; margin-top: $spacer;
margin-bottom: $spacer; margin-bottom: $spacer;
border: .2rem dashed $brand-grey-lighter; border: .2rem dashed $brand-grey-lighter;
border-radius: 1rem; border-radius: $border-radius * 2;
padding: $spacer; padding: $spacer;
background: $brand-white; background: $brand-white;
transition: .2s ease-out; transition: .2s ease-out;
@ -17,6 +17,7 @@
color: $brand-grey-light; color: $brand-grey-light;
} }
&:hover,
&:focus, &:focus,
&:active { &:active {
border-color: $brand-grey-light; border-color: $brand-grey-light;

View File

@ -6,7 +6,7 @@ export default function Dropzone({
handleOnDrop, handleOnDrop,
disabled disabled
}: { }: {
handleOnDrop(files: FileList): void handleOnDrop(files: File[]): void
disabled?: boolean disabled?: boolean
}) { }) {
const onDrop = useCallback(acceptedFiles => handleOnDrop(acceptedFiles), [ const onDrop = useCallback(acceptedFiles => handleOnDrop(acceptedFiles), [

View File

@ -8,13 +8,13 @@ import Dropzone from '../../../../components/molecules/Dropzone'
import { formatBytes, pingUrl } from './utils' import { formatBytes, pingUrl } from './utils'
import styles from './index.module.scss' import styles from './index.module.scss'
export default function Ipfs({ addFile }: { addFile(url: string): void }) { const config = {
const config = { host: 'ipfs.infura.io',
host: 'ipfs.infura.io', port: '5001',
port: '5001', protocol: 'https'
protocol: 'https' }
}
export default function Ipfs({ addFile }: { addFile(url: string): void }) {
const { const {
ipfs, ipfs,
ipfsVersion, ipfsVersion,
@ -26,16 +26,24 @@ 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(buffer: Buffer) { async function saveToIpfs(
data: File | Buffer | ReadableStream,
size: number
) {
const totalSize = formatBytes(size, 0)
setLoading(true) setLoading(true)
setMessage('Adding to remote IPFS node<br />') setMessage(`Adding to IPFS<br /><small>0/${totalSize}</small><br />`)
try { try {
const response = await ipfs.add(buffer, { const response = await ipfs.add(data, {
progress: (length: number) => progress: (length: number) =>
setMessage( setMessage(
`Adding to remote IPFS node<br /> `Adding to IPFS<br />
${formatBytes(length, 0)}` <small>${formatBytes(
length,
0
)}/${totalSize}</small><br />`
) )
}) })
@ -43,9 +51,9 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
console.log(`File added: ${cid}`) console.log(`File added: ${cid}`)
// Ping gateway url to make it globally available, // Ping gateway url to make it globally available,
// but store ipfs.io url in DDO. // but store native url in DDO.
// https://ipfs.github.io/public-gateway-checker/ // https://ipfs.github.io/public-gateway-checker/
const url = `https://ipfs.io/ipfs/${cid}` const url = `ipfs://${cid}`
const urlGateway = `https://ipfs.infura.io/ipfs/${cid}` const urlGateway = `https://ipfs.infura.io/ipfs/${cid}`
setMessage('Checking IPFS gateway URL') setMessage('Checking IPFS gateway URL')
@ -54,22 +62,13 @@ export default function Ipfs({ addFile }: { addFile(url: string): void }) {
// add IPFS url to file.url // add IPFS url to file.url
addFile(url) addFile(url)
} catch (error) { } catch (error) {
console.error(error.message) console.error(`Adding to IPFS failed: ${error.message}`)
setLoading(false) setLoading(false)
} }
} }
function handleOnDrop(files: any) { function handleOnDrop(files: File[]) {
const reader: any = new FileReader() files.forEach((file: File) => saveToIpfs(file, file.size))
files &&
files.forEach((file: File) => {
reader.readAsArrayBuffer(file)
reader.onloadend = () => {
const buffer: any = Buffer.from(reader.result)
saveToIpfs(buffer)
}
})
} }
return ( return (