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

support adding files from IPFS url

This commit is contained in:
Matthias Kretschmann 2019-09-06 13:15:48 +02:00
parent 10b662343f
commit 475cade27f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
9 changed files with 64 additions and 20 deletions

View File

@ -9125,10 +9125,13 @@
"unc-path-regex": "^0.1.2"
}
},
"is-url": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz",
"integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww=="
"is-url-superb": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-url-superb/-/is-url-superb-3.0.0.tgz",
"integrity": "sha512-3faQP+wHCGDQT1qReM5zCPx2mxoal6DzbzquFlCYJLWyy4WPTved33ea2xFbX37z4NoriEwZGIYhFtx8RUB5wQ==",
"requires": {
"url-regex": "^5.0.0"
}
},
"is-utf8": {
"version": "0.2.1",
@ -16371,6 +16374,11 @@
"resolved": "https://registry.npmjs.org/tiny-warning/-/tiny-warning-1.0.3.tgz",
"integrity": "sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA=="
},
"tlds": {
"version": "1.203.1",
"resolved": "https://registry.npmjs.org/tlds/-/tlds-1.203.1.tgz",
"integrity": "sha512-7MUlYyGJ6rSitEZ3r1Q1QNV8uSIzapS8SmmhSusBuIc7uIxPPwsKllEP0GRp1NS6Ik6F+fRZvnjDWm3ecv2hDw=="
},
"tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
@ -17010,6 +17018,22 @@
"prepend-http": "^1.0.1"
}
},
"url-regex": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/url-regex/-/url-regex-5.0.0.tgz",
"integrity": "sha512-O08GjTiAFNsSlrUWfqF1jH0H1W3m35ZyadHrGv5krdnmPPoxP27oDTqux/579PtaroiSGm5yma6KT1mHFH6Y/g==",
"requires": {
"ip-regex": "^4.1.0",
"tlds": "^1.203.0"
},
"dependencies": {
"ip-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.1.0.tgz",
"integrity": "sha512-pKnZpbgCTfH/1NLIlOduP/V+WRXzC2MOz3Qo8xmxk8C5GudJLgK5QyLVXOSWy3ParAH7Eemurl3xjv/WXYFvMA=="
}
}
},
"url-set-query": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/url-set-query/-/url-set-query-1.0.0.tgz",

View File

@ -23,7 +23,7 @@
"ethereum-blockies": "github:MyEtherWallet/blockies",
"filesize": "^4.1.2",
"history": "^4.9.0",
"is-url": "^1.2.4",
"is-url-superb": "^3.0.0",
"moment": "^2.24.0",
"query-string": "^6.8.2",
"react": "16.8.6",

View File

@ -30,6 +30,7 @@ interface InputProps {
rows?: number
group?: any
multiple?: boolean
pattern?: string
}
interface InputState {

View File

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react'
import isUrl from 'is-url'
import isUrl from 'is-url-superb'
import Input from '../../../components/atoms/Form/Input'
import Button from '../../../components/atoms/Button'
import styles from './ItemForm.module.scss'
@ -37,7 +37,7 @@ export default class ItemForm extends PureComponent<
return
}
if (url && !isUrl(url)) {
if (url && !url.includes('ipfs://') && !isUrl(url)) {
this.setState({ noUrl: true })
return
}

View File

@ -1 +1,2 @@
SENDGRID_API_KEY='xxx'
IPFS_GATEWAY_URL='https://gateway.ipfs.io'

View File

@ -4,12 +4,12 @@
This folder contains server component written in TypeScript using [Express](https://expressjs.com). The server provides various microservices.
- [Get Started](#Get-Started)
- [✨ API Documentation](#-API-Documentation)
- [Url Checker](#Url-Checker)
- [Report](#Report)
- [🎁 Contributing](#-Contributing)
- [🏛 License](#-License)
- [Get Started](#get-started)
- [✨ API Documentation](#-api-documentation)
- [Url Checker](#url-checker)
- [Report](#report)
- [🎁 Contributing](#-contributing)
- [🏛 License](#-license)
## Get Started
@ -36,6 +36,12 @@ Url Checker returns size and additional information about requested file. This s
}
```
```json
{
"url": "ipfs://QmQfpdcMWnLTXKKW9GPV7NgtEugghgD6HgzSF6gSrp2mL9"
}
```
**Response: Success**
```json

View File

@ -1,7 +1,9 @@
import 'dotenv/config'
const config = {
app: {
port: 4000
}
app: { port: 4000 },
sendgridApiKey: process.env.SENDGRID_API_KEY,
ipfsGatewayUrl: process.env.IPFS_GATEWAY_URL || 'https://gateway.ipfs.io'
}
export default config

View File

@ -1,8 +1,8 @@
import { Router, Request, Response } from 'express'
import SendgridMail from '@sendgrid/mail'
import 'dotenv/config'
import config from '../config/config'
SendgridMail.setApiKey(process.env.SENDGRID_API_KEY)
SendgridMail.setApiKey(config.sendgridApiKey)
export class ReportRouter {
public router: Router

View File

@ -1,5 +1,6 @@
import { Router, Request, Response } from 'express'
import request from 'request'
import config from '../config/config'
export class UrlCheckRouter {
public router: Router
@ -12,13 +13,22 @@ export class UrlCheckRouter {
}
public checkUrl(req: Request, res: Response) {
if (!req.body.url) {
let { url } = req.body
if (!url) {
return res.send({ status: 'error', message: 'missing url' })
}
// map native IPFS URLs to gateway URLs
if (url.includes('ipfs://')) {
const cid = url.split('ipfs://')[1]
url = `${config.ipfsGatewayUrl}/ipfs/${cid}`
}
request(
{
method: 'HEAD',
url: req.body.url,
url,
headers: { Range: 'bytes=0-' }
},
(error, response) => {