mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* update version and file Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * update label and description Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * remove dot Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * remove helper props so we don't add them on chain Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * bump ocean.js to v1.1.2 * build fix Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
import {
|
|
downloadFileBrowser,
|
|
FileInfo,
|
|
LoggerInstance,
|
|
ProviderInstance
|
|
} from '@oceanprotocol/lib'
|
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
|
import Web3 from 'web3'
|
|
|
|
// TODO: Why do we have these one line functions ?!?!?!
|
|
export async function getEncryptedFiles(
|
|
files: any,
|
|
providerUrl: string
|
|
): Promise<string> {
|
|
try {
|
|
// https://github.com/oceanprotocol/provider/blob/v4main/API.md#encrypt-endpoint
|
|
const response = await ProviderInstance.encrypt(files, providerUrl)
|
|
return response
|
|
} catch (error) {
|
|
console.error('Error parsing json: ' + error.message)
|
|
}
|
|
}
|
|
|
|
export async function getFileDidInfo(
|
|
did: string,
|
|
serviceId: string,
|
|
providerUrl: string
|
|
): Promise<FileInfo[]> {
|
|
try {
|
|
const response = await ProviderInstance.checkDidFiles(
|
|
did,
|
|
serviceId as any, // TODO: why does ocean.js want a number here?
|
|
providerUrl
|
|
)
|
|
return response
|
|
} catch (error) {
|
|
LoggerInstance.error(error.message)
|
|
}
|
|
}
|
|
|
|
export async function getFileUrlInfo(
|
|
url: string,
|
|
providerUrl: string
|
|
): Promise<FileInfo[]> {
|
|
try {
|
|
const response = await ProviderInstance.checkFileUrl(url, providerUrl)
|
|
return response
|
|
} catch (error) {
|
|
LoggerInstance.error(error.message)
|
|
}
|
|
}
|
|
|
|
export async function downloadFile(
|
|
web3: Web3,
|
|
asset: AssetExtended,
|
|
accountId: string,
|
|
validOrderTx?: string
|
|
) {
|
|
const downloadUrl = await ProviderInstance.getDownloadUrl(
|
|
asset.id,
|
|
accountId,
|
|
asset.services[0].id,
|
|
0,
|
|
validOrderTx || asset.accessDetails.validOrderTx,
|
|
asset.services[0].serviceEndpoint,
|
|
web3
|
|
)
|
|
await downloadFileBrowser(downloadUrl)
|
|
}
|