1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
This commit is contained in:
alexcos20 2020-03-30 15:09:23 +03:00
parent 5289443cde
commit 8bfa7ba593
5 changed files with 32 additions and 43 deletions

View File

@ -5,7 +5,6 @@ import { EditableMetaData } from '../ddo/MetaData'
import { Logger } from '../utils' import { Logger } from '../utils'
import { WebServiceConnector } from '../ocean/utils/WebServiceConnector' import { WebServiceConnector } from '../ocean/utils/WebServiceConnector'
const apiPath = '/api/v1/aquarius/assets/ddo' const apiPath = '/api/v1/aquarius/assets/ddo'
export interface QueryResult { export interface QueryResult {
@ -262,7 +261,6 @@ export class Aquarius {
return result return result
} }
public async editMetadata( public async editMetadata(
did: DID | string, did: DID | string,
newMetadata: EditableMetaData, newMetadata: EditableMetaData,
@ -271,17 +269,15 @@ export class Aquarius {
): Promise<string> { ): Promise<string> {
did = did && DID.parse(did) did = did && DID.parse(did)
const fullUrl = `${this.url}${apiPath}/metadata/update/${did.getDid()}` const fullUrl = `${this.url}${apiPath}/metadata/update/${did.getDid()}`
let data = Object() const data = Object()
if (newMetadata.description != null) if (newMetadata.description != null) data.description = newMetadata.description
data.description = newMetadata.description if (newMetadata.title != null) data.title = newMetadata.title
if (newMetadata.title != null)
data.title = newMetadata.title
if (newMetadata.servicePrices != null) if (newMetadata.servicePrices != null)
data.servicePrices = newMetadata.servicePrices data.servicePrices = newMetadata.servicePrices
if (newMetadata.links != null) { if (newMetadata.links != null) {
data.links = [] data.links = []
for (const [name, url] of Object.entries(newMetadata.links)) { for (const [name, url] of Object.entries(newMetadata.links)) {
let asample = Object() const asample = Object()
asample.name = name asample.name = name
asample.url = url asample.url = url
asample.type = 'sample' asample.type = 'sample'
@ -291,10 +287,7 @@ export class Aquarius {
data.updated = updated data.updated = updated
data.signature = signature data.signature = signature
const result = await this.fetch const result = await this.fetch
.put( .put(fullUrl, JSON.stringify(data))
fullUrl,
JSON.stringify(data)
)
.then((response: any) => { .then((response: any) => {
if (response.ok) { if (response.ok) {
return response.text return response.text
@ -350,7 +343,6 @@ export class Aquarius {
return result return result
} }
public getServiceEndpoint(did: DID) { public getServiceEndpoint(did: DID) {
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}` return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
} }

View File

@ -277,14 +277,14 @@ export interface MetaData {
curation?: Curation curation?: Curation
} }
export interface ServicePrices{ export interface ServicePrices {
serviceIndex: number, serviceIndex: number
price: string price: string
} }
export interface EditableMetaData{ export interface EditableMetaData {
description?: string, description?: string
title?: string, title?: string
links?: { [name: string]: string }[], links?: { [name: string]: string }[]
servicePrices?: ServicePrices[] servicePrices?: ServicePrices[]
} }

View File

@ -395,9 +395,9 @@ export class OceanAssets extends Instantiable {
oldDdo.updated, oldDdo.updated,
account account
) )
let result=null let result = null
if (signature != null) if (signature != null)
result=await this.ocean.aquarius.editMetadata( result = await this.ocean.aquarius.editMetadata(
did, did,
newMetadata, newMetadata,
oldDdo.updated, oldDdo.updated,
@ -407,17 +407,14 @@ export class OceanAssets extends Instantiable {
return result return result
} }
public async retire( public async retire(did: string, account: Account): Promise<string> {
did: string,
account: Account
): Promise<string> {
const oldDdo = await this.ocean.aquarius.retrieveDDO(did) const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
// get a signature // get a signature
const signature = await this.ocean.utils.signature.signForAquarius( const signature = await this.ocean.utils.signature.signForAquarius(
oldDdo.updated, oldDdo.updated,
account account
) )
let result=null let result = null
if (signature != null) if (signature != null)
result = await this.ocean.aquarius.retire(did, oldDdo.updated, signature) result = await this.ocean.aquarius.retire(did, oldDdo.updated, signature)
return result return result

View File

@ -52,8 +52,7 @@ export class WebServiceConnector {
'Content-type': 'application/json' 'Content-type': 'application/json'
} }
}) })
} } else {
else {
return this.fetch(url, { return this.fetch(url, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
@ -61,7 +60,6 @@ export class WebServiceConnector {
} }
}) })
} }
} }
public async downloadFile( public async downloadFile(

View File

@ -92,7 +92,7 @@ describe('Asset Owners', () => {
).toString() ).toString()
) )
) )
} catch { } } catch {}
await ocean.assets.order(ddo.id, account2) await ocean.assets.order(ddo.id, account2)
// Access granted // Access granted
const { length: finalLength2 } = await ocean.assets.consumerAssets( const { length: finalLength2 } = await ocean.assets.consumerAssets(
@ -115,23 +115,25 @@ describe('Asset Owners', () => {
it('should be able to update metadata', async () => { it('should be able to update metadata', async () => {
const { id } = await ocean.assets.create(metadata as any, account1) const { id } = await ocean.assets.create(metadata as any, account1)
let newMetaData = {title: "New title", description: "New description"}; const newMetaData = { title: 'New title', description: 'New description' }
await ocean.assets.editMetadata(id,newMetaData,account1) await ocean.assets.editMetadata(id, newMetaData, account1)
const newDDO = await ocean.assets.resolve(id) const newDDO = await ocean.assets.resolve(id)
assert.equal(newDDO['service'][0]['attributes']['main']['name'], "New title") assert.equal(newDDO.service[0].attributes.main.name, 'New title')
assert.equal(newDDO['service'][0]['attributes']['additionalInformation']['description'], "New description") assert.equal(
newDDO.service[0].attributes.additionalInformation.description,
'New description'
)
}) })
it('should be able to retire metadata', async () => { it('should be able to retire metadata', async () => {
const { id } = await ocean.assets.create(metadata as any, account1) const { id } = await ocean.assets.create(metadata as any, account1)
await ocean.assets.retire(id,account1) await ocean.assets.retire(id, account1)
const newDDO = await ocean.assets.resolve(id) const newDDO = await ocean.assets.resolve(id)
assert.equal(newDDO, null) assert.equal(newDDO, null)
}) })
}) })