1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

add getAssetMetadata() function

This commit is contained in:
Miquel A. Cabot 2022-07-14 13:35:49 +02:00
parent 8b952c6b05
commit 76471f3677

View File

@ -146,6 +146,37 @@ export class Aquarius {
return status
}
/**
* Search over the DDOs using a query.
* @param {string} did DID of the asset
* @param {AbortSignal} signal abort signal
* @return {Promise<QueryResult>}
*/
public async getAssetMetadata(did: string, signal?: AbortSignal): Promise<any> {
const path = this.aquariusURL + '/api/aquarius/assets/metadata/' + did
try {
const response = await fetch(path, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
signal: signal
})
if (response.ok) {
return response.json()
} else {
throw new Error(
'getAssetMetadata failed: ' + response.status + response.statusText
)
}
} catch (error) {
LoggerInstance.error('Error getting metadata: ', error)
throw new Error('Error getting metadata: ', error)
}
}
/**
* Search over the DDOs using a query.
* @param {SearchQuery} query Query to filter the DDOs.
@ -168,8 +199,7 @@ export class Aquarius {
if (response.ok) {
return response.json()
} else {
LoggerInstance.error('querySearch failed: ', response.status, response.statusText)
return null
throw new Error('querySearch failed: ' + response.status + response.statusText)
}
} catch (error) {
LoggerInstance.error('Error querying metadata: ', error)