mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
* [KianYee] #459 enhance file info function * [KianYee] #459 enhance file info function * [KianYee] Fix issue * [KianYee] #459 fix codeclimate * [KianYee] #459 add intergration test * [KianYee] Add integration test * [KianYee] #459 Fix bug * [KianYee] #459 Slipt function into 2 * [KianYee] removed unused import * [KianYee] update test case description
This commit is contained in:
parent
23f319b8a8
commit
04c2a9b09a
@ -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<File[]>} urlDetails
|
||||
*/
|
||||
public async fileinfo(url: string | DID): Promise<File[]> {
|
||||
let args
|
||||
public async fileinfo(url: string): Promise<File[]> {
|
||||
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<boolean> {
|
||||
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>} string
|
||||
|
@ -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 () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user