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", "cross-fetch": "^3.1.4",
"crypto-js": "^4.0.0", "crypto-js": "^4.0.0",
"decimal.js": "^10.2.1", "decimal.js": "^10.2.1",
"ethereumjs-util": "^7.1.3",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"save-file": "^2.3.1", "save-file": "^2.3.1",
"web3": ">=1.3.5", "web3": ">=1.3.5",

View File

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

View File

@ -1,32 +1,25 @@
import React, { ReactElement, useState } from 'react' import React, { ReactElement, useState } from 'react'
import { useField } from 'formik' import { useField, useFormikContext } from 'formik'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import FileInfo from './Info' import FileInfo from './Info'
import UrlInput from '../URLInput' import UrlInput from '../URLInput'
import { InputProps } from '@shared/FormInput' 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 { 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 { export default function FilesInput(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props.name) const [field, meta, helpers] = useField(props.name)
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const { chainId } = useWeb3() const { values } = useFormikContext<FormPublishData>()
const newCancelToken = useCancelToken()
function loadFileInfo(url: string) { function loadFileInfo(url: string) {
const config = getOceanConfig(chainId || 1) const providerUri = values.services[0].providerUrl.url
async function validateUrl() { async function validateUrl() {
try { try {
setIsLoading(true) setIsLoading(true)
const checkedFile = await getFileInfo( const checkedFile = await getFileInfo(url, providerUri)
url,
config?.providerUri,
newCancelToken()
)
checkedFile && helpers.setValue([{ url, ...checkedFile[0] }]) checkedFile && helpers.setValue([{ url, ...checkedFile[0] }])
} catch (error) { } catch (error) {
toast.error('Could not fetch file info. Please check URL and try again') 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 asset = values?.services?.[0].files?.[0].url || ddo.id
const providerUrl = const providerUrl =
values?.services[0].providerUrl || oceanConfig.providerUri values?.services[0].providerUrl.url || oceanConfig.providerUri
try { try {
const fileInfoResponse = await getFileInfo( const fileInfoResponse = await getFileInfo(asset, providerUrl)
asset,
oceanConfig.providerUri,
newCancelToken()
)
fileInfoResponse && setFileMetadata(fileInfoResponse[0]) fileInfoResponse && setFileMetadata(fileInfoResponse[0])
setFileIsLoading(false) setFileIsLoading(false)
} catch (error) { } catch (error) {