mirror of
https://github.com/oceanprotocol/ipfs
synced 2025-02-14 21:10:37 +01:00
Merge pull request #22 from oceanprotocol/feature/updates
Fixes and updates
This commit is contained in:
commit
dc7c348307
9110
package-lock.json
generated
9110
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -12,32 +12,32 @@
|
|||||||
"author": "Matthias Kretschmann <matthias@oceanprotocol.com>",
|
"author": "Matthias Kretschmann <matthias@oceanprotocol.com>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdx-js/loader": "^1.5.5",
|
"@mdx-js/loader": "^1.6.5",
|
||||||
"@next/mdx": "^9.2.1",
|
"@next/mdx": "^9.4.4",
|
||||||
"@oceanprotocol/art": "^2.2.0",
|
"@oceanprotocol/art": "^2.2.0",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
"ipfs-http-client": "^42.0.0",
|
"ipfs-http-client": "^44.1.1",
|
||||||
"next": "9.2.2",
|
"next": "^9.4.4",
|
||||||
"next-seo": "^4.1.0",
|
"next-seo": "^4.5.0",
|
||||||
"next-svgr": "^0.0.2",
|
"next-svgr": "^0.0.2",
|
||||||
"react": "^16.12.0",
|
"react": "^16.13.1",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.13.1",
|
||||||
"react-dropzone": "^11.0.0"
|
"react-dropzone": "^11.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/next-seo": "^1.10.0",
|
"@types/next-seo": "^1.10.0",
|
||||||
"@types/node": "^14.0.0",
|
"@types/node": "^14.0.0",
|
||||||
"@types/react": "^16.9.19",
|
"@types/react": "^16.9.32",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.19.1",
|
"@typescript-eslint/eslint-plugin": "^3.1.0",
|
||||||
"@typescript-eslint/parser": "^2.19.1",
|
"@typescript-eslint/parser": "^3.1.0",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^7.1.0",
|
||||||
"eslint-config-oceanprotocol": "^1.5.0",
|
"eslint-config-oceanprotocol": "^1.5.0",
|
||||||
"eslint-config-prettier": "^6.10.0",
|
"eslint-config-prettier": "^6.11.0",
|
||||||
"eslint-plugin-prettier": "^3.1.2",
|
"eslint-plugin-prettier": "^3.1.3",
|
||||||
"eslint-plugin-react": "^7.18.3",
|
"eslint-plugin-react": "^7.20.0",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^2.0.5",
|
||||||
"typescript": "^3.7.5"
|
"typescript": "^3.9.5"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -27,7 +27,6 @@ export default function Layout({
|
|||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
images: [{ url: `${url}/share.png` }],
|
images: [{ url: `${url}/share.png` }],
|
||||||
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
||||||
site_name: title
|
site_name: title
|
||||||
}}
|
}}
|
||||||
twitter={{
|
twitter={{
|
||||||
|
@ -16,11 +16,11 @@ const ipfsConfig: IpfsConfig = {
|
|||||||
|
|
||||||
export default function Add() {
|
export default function Add() {
|
||||||
const { ipfs, isIpfsReady, ipfsError } = useIpfsApi(ipfsConfig)
|
const { ipfs, isIpfsReady, ipfsError } = useIpfsApi(ipfsConfig)
|
||||||
const [fileHash, setFileHash] = useState()
|
const [fileHash, setFileHash] = useState('')
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [message, setMessage] = useState()
|
const [message, setMessage] = useState('')
|
||||||
const [error, setError] = useState()
|
const [error, setError] = useState('')
|
||||||
const [fileSize, setFileSize] = useState()
|
const [fileSize, setFileSize] = useState('')
|
||||||
const [fileSizeReceived] = useState('')
|
const [fileSizeReceived] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -34,7 +34,7 @@ export default function Add() {
|
|||||||
if (!acceptedFiles[0]) return
|
if (!acceptedFiles[0]) return
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError(null)
|
setError('')
|
||||||
|
|
||||||
const totalSize = formatBytes(acceptedFiles[0].size, 0)
|
const totalSize = formatBytes(acceptedFiles[0].size, 0)
|
||||||
setFileSize(totalSize)
|
setFileSize(totalSize)
|
||||||
@ -54,7 +54,7 @@ export default function Add() {
|
|||||||
<div className={styles.add}>
|
<div className={styles.add}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Spinner message={message} />
|
<Spinner message={message} />
|
||||||
) : fileHash ? (
|
) : fileHash !== '' ? (
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
|
@ -13,7 +13,7 @@ export default function Dropzone({
|
|||||||
multiple?: boolean
|
multiple?: boolean
|
||||||
error?: string
|
error?: string
|
||||||
}) {
|
}) {
|
||||||
const onDrop = useCallback(acceptedFiles => handleOnDrop(acceptedFiles), [
|
const onDrop = useCallback((acceptedFiles) => handleOnDrop(acceptedFiles), [
|
||||||
handleOnDrop
|
handleOnDrop
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ export default function Dropzone({
|
|||||||
`Drop it like it's hot!`
|
`Drop it like it's hot!`
|
||||||
) : multiple ? (
|
) : multiple ? (
|
||||||
`Drag 'n' drop some files here, or click to select files`
|
`Drag 'n' drop some files here, or click to select files`
|
||||||
) : error ? (
|
) : error || error !== '' ? (
|
||||||
<div className={styles.error}>{error}</div>
|
<div className={styles.error}>{error}</div>
|
||||||
) : (
|
) : (
|
||||||
`Drag 'n' drop a file here, or click to select a file`
|
`Drag 'n' drop a file here, or click to select a file`
|
||||||
|
@ -13,7 +13,7 @@ export default function Footer() {
|
|||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{links.map(link => (
|
{links.map((link) => (
|
||||||
<a key={link.name} href={link.url}>
|
<a key={link.name} href={link.url}>
|
||||||
{link.name}
|
{link.name}
|
||||||
</a>
|
</a>
|
||||||
|
@ -18,7 +18,7 @@ export default function useIpfsApi(config: IpfsConfig) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initIpfs() {
|
async function initIpfs() {
|
||||||
if (ipfs !== null) return
|
if (ipfs !== null) return
|
||||||
// eslint-disable-next-line
|
|
||||||
ipfs = await ipfsClient(config)
|
ipfs = await ipfsClient(config)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -44,7 +44,6 @@ export default function useIpfsApi(config: IpfsConfig) {
|
|||||||
}, [config])
|
}, [config])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// just like componentWillUnmount()
|
|
||||||
return function cleanup() {
|
return function cleanup() {
|
||||||
if (ipfs) {
|
if (ipfs) {
|
||||||
setIpfsReady(false)
|
setIpfsReady(false)
|
||||||
|
36
src/utils.ts
36
src/utils.ts
@ -9,33 +9,27 @@ export function formatBytes(a: number, b: number) {
|
|||||||
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
|
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
|
||||||
}
|
}
|
||||||
|
|
||||||
const streamFiles = (ipfs: any, file: any) =>
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const stream = ipfs.addReadableStream({
|
|
||||||
wrapWithDirectory: true
|
|
||||||
// progress: (length: number) => setFileSizeReceived(formatBytes(length, 0))
|
|
||||||
})
|
|
||||||
|
|
||||||
stream.on('data', (data: any) => {
|
|
||||||
console.log(`Added ${data.path} hash: ${data.hash}`)
|
|
||||||
|
|
||||||
// The last data event will contain the directory hash
|
|
||||||
if (data.path === '') resolve(data.hash)
|
|
||||||
})
|
|
||||||
|
|
||||||
stream.on('error', reject)
|
|
||||||
stream.write(file)
|
|
||||||
stream.end()
|
|
||||||
})
|
|
||||||
|
|
||||||
export async function addToIpfs(files: File[], ipfs: any) {
|
export async function addToIpfs(files: File[], ipfs: any) {
|
||||||
const file = [...files][0]
|
const file = [...files][0]
|
||||||
const fileDetails = { path: file.name, content: file }
|
const fileDetails = { path: file.name, content: file }
|
||||||
|
|
||||||
const directoryCid = await streamFiles(ipfs, fileDetails)
|
const source = await ipfs.add(fileDetails, {
|
||||||
const cid = `${directoryCid}/${file.name}`
|
wrapWithDirectory: true,
|
||||||
|
progress: (prog: number) => console.log(`received: ${prog}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
for await (const ipfsFile of source) {
|
||||||
|
// The last path will contain the directory hash
|
||||||
|
if (ipfsFile.path === '') {
|
||||||
|
const cid = `${ipfsFile.cid.toString()}/${file.name}`
|
||||||
return cid
|
return cid
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function pingUrl(url: string) {
|
export async function pingUrl(url: string) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user