1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Integrate provider fileinfo (#965)

* provider functions added

* working validation

* fixes, comments deleted

* lint fix, comment deleted

* fixes over the provider functions integration

* remove unused provider.ts exports

* provider checkFileUrl() integration

* provider encrypt method changes

* use fetch method

* axios request reused

* dependency removed

* getFileInfo fixes

* remove unused const

* function call fix

* use providerUrl form value

Co-authored-by: ClaudiaHolhos <claudia@oceanprotocol.com>
This commit is contained in:
claudiaHash 2022-01-12 19:02:47 +02:00 committed by GitHub
parent 7d4d526d21
commit 44114345bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 37 deletions

1
package-lock.json generated
View File

@ -115,6 +115,7 @@
"cross-fetch": "^3.1.4",
"crypto-js": "^4.0.0",
"decimal.js": "^10.2.1",
"ethereumjs-util": "^7.1.3",
"fs": "0.0.1-security",
"save-file": "^2.3.1",
"web3": ">=1.3.5",

View File

@ -32,27 +32,22 @@ export async function getEncryptedFiles(
export async function getFileInfo(
url: string,
providerUrl: string,
cancelToken: CancelToken
providerUrl: string
): Promise<FileMetadata[]> {
try {
// TODO: what was the point of this?
// if (url instanceof DID) postBody = { did: url.getDid() }
// else postBody = { url }
const postBody = { url, type: 'url' }
const response: AxiosResponse<FileMetadata[]> = await axios.post(
`${providerUrl}/api/services/fileinfo`,
postBody,
{ cancelToken }
const response = await ProviderInstance.checkFileUrl(
url,
providerUrl,
(method: Method, path: string, body: string) => {
return fetch(path, {
method: method,
body: body,
headers: { 'Content-Type': 'application/json' }
})
}
)
if (!response || response.status !== 200 || !response.data) return
return response.data
return response
} catch (error) {
if (axios.isCancel(error)) {
LoggerInstance.log(error.message)
} else {
LoggerInstance.error(error.message)
}
}
}

View File

@ -1,32 +1,25 @@
import React, { ReactElement, useState } from 'react'
import { useField } from 'formik'
import { useField, useFormikContext } from 'formik'
import { toast } from 'react-toastify'
import FileInfo from './Info'
import UrlInput from '../URLInput'
import { InputProps } from '@shared/FormInput'
import { getFileInfo } from '@utils/provider'
import { useWeb3 } from '@context/Web3'
import { getOceanConfig } from '@utils/ocean'
import { useCancelToken } from '@hooks/useCancelToken'
import { initialValues } from 'src/components/Publish/_constants'
import { getFileInfo } from '@utils/provider'
import { FormPublishData } from 'src/components/Publish/_types'
export default function FilesInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name)
const [isLoading, setIsLoading] = useState(false)
const { chainId } = useWeb3()
const newCancelToken = useCancelToken()
const { values } = useFormikContext<FormPublishData>()
function loadFileInfo(url: string) {
const config = getOceanConfig(chainId || 1)
const providerUri = values.services[0].providerUrl.url
async function validateUrl() {
try {
setIsLoading(true)
const checkedFile = await getFileInfo(
url,
config?.providerUri,
newCancelToken()
)
const checkedFile = await getFileInfo(url, providerUri)
checkedFile && helpers.setValue([{ url, ...checkedFile[0] }])
} catch (error) {
toast.error('Could not fetch file info. Please check URL and try again')

View File

@ -66,14 +66,10 @@ export default function AssetActions({
const asset = values?.services?.[0].files?.[0].url || ddo.id
const providerUrl =
values?.services[0].providerUrl || oceanConfig.providerUri
values?.services[0].providerUrl.url || oceanConfig.providerUri
try {
const fileInfoResponse = await getFileInfo(
asset,
oceanConfig.providerUri,
newCancelToken()
)
const fileInfoResponse = await getFileInfo(asset, providerUrl)
fileInfoResponse && setFileMetadata(fileInfoResponse[0])
setFileIsLoading(false)
} catch (error) {