diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index af4896db..0b301d92 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -9,6 +9,7 @@ import { MetadataAlgorithm } from '../ddo/interfaces/MetadataAlgorithm' import { Versions } from '../ocean/Versions' import { DDO } from '../ddo/DDO' import DID from '../ocean/DID' +import { Service } from '../ddo/interfaces' export interface ServiceEndpoint { serviceName: string @@ -129,12 +130,9 @@ export class Provider extends Instantiable { * @param {String | DID} url or did * @return {Promise} urlDetails */ - public async fileinfo(url: string | DID): Promise { - let args + public async fileinfo(url: string): Promise { + const args = { url } const files: File[] = [] - if (url instanceof DID) { - args = { did: url.getDid() } - } else args = { url } const path = this.getFileinfoEndpoint() ? this.getFileinfoEndpoint().urlPath : null if (!path) return null try { @@ -149,6 +147,22 @@ export class Provider extends Instantiable { } } + public async isFileConsumable(did: DID, serviceIndex: number): Promise { + const args = { did: did.getDid() } + const ddo = await this.ocean.metadataCache.retrieveDDO(did) + if (!ddo) return false + const service: Service = ddo.findServiceById(serviceIndex) + if (!service) return false + const path = service.serviceEndpoint + '/api/v1/services/fileinfo' + try { + const response = await this.ocean.utils.fetch.post(path, JSON.stringify(args)) + const results = await response.json() + return results[0].valid + } catch (e) { + return false + } + } + /** Get nonce from provider * @param {String} consumerAddress * @return {Promise} string diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index bbca40d4..05bbbd4e 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -448,11 +448,13 @@ describe('Marketplace flow', () => { assert(parseInt(metaData.attributes.main.timeout) === parseInt(newTimeout.toFixed())) }) - it('Alice should check if her asset has valid url(s)', async () => { + it('Alice should check if her asset is consumable', async () => { + const service = ddo.findServiceByType('access') + assert(service !== null) + const serviceIndex = service.index const did: DID = DID.generate(noDidPrefixed(ddo.id)) - const response = await ocean.provider.fileinfo(did) - assert(response[0].contentLength === '1161') - assert(response[0].contentType === 'application/json') + const response = await ocean.provider.isFileConsumable(did, serviceIndex) + assert(response === true) }) it('Alice should create a FRE pricing for her asset', async () => {