mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Draft for Dynamic provider endpoints. Need a feedback about the function modifications in Provider.ts. Need to do unit tests.
This commit is contained in:
parent
16c21e1ecb
commit
03ed3f6200
@ -21,6 +21,7 @@ const apiPath = '/api/v1/services'
|
||||
export class Provider extends Instantiable {
|
||||
public nonce: string
|
||||
private baseUrl: string
|
||||
public validServiceEndpoints: any
|
||||
|
||||
public get url(): string {
|
||||
return this.baseUrl
|
||||
@ -186,6 +187,42 @@ export class Provider extends Instantiable {
|
||||
return destination
|
||||
}
|
||||
|
||||
public async getServiceEndpoints() {
|
||||
let fetch: any
|
||||
fetch = this.ocean.utils.fetch.get(this.url)
|
||||
if (this.validServiceEndpoints != null) {
|
||||
this.validServiceEndpoints = await fetch
|
||||
.then((response: Response) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
|
||||
this.logger.error('Finding the service endpoints failed:', response.status, response.statusText)
|
||||
|
||||
return null
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
this.logger.error('Error with service endpoints')
|
||||
this.logger.error(error.message)
|
||||
throw error
|
||||
})
|
||||
}
|
||||
return this.validServiceEndpoints;
|
||||
}
|
||||
|
||||
public getEndpointURL(
|
||||
serviceName : string
|
||||
) : string {
|
||||
var method: string
|
||||
var urlEndpoint: string
|
||||
this.validServiceEndpoints = this.getServiceEndpoints()
|
||||
method = this.validServiceEndpoints['serviceEndpoints'][0]
|
||||
urlEndpoint = this.validServiceEndpoints['serviceEndpoints'][1]
|
||||
urlEndpoint = urlEndpoint.replace(`${apiPath}`, '')
|
||||
return `${this.getURI()}${urlEndpoint}`
|
||||
|
||||
}
|
||||
|
||||
public async compute(
|
||||
method: string,
|
||||
did: string,
|
||||
@ -242,7 +279,6 @@ export class Provider extends Instantiable {
|
||||
// 'algorithmDid': alg_ddo.did,
|
||||
// 'algorithmMeta': {},
|
||||
// 'algorithmDataToken': alg_data_token
|
||||
|
||||
// switch fetch method
|
||||
let fetch
|
||||
switch (method) {
|
||||
@ -288,11 +324,13 @@ export class Provider extends Instantiable {
|
||||
}
|
||||
|
||||
public getInitializeEndpoint(): string {
|
||||
return `${this.url}${apiPath}/initialize`
|
||||
//return `${this.url}${apiPath}/initialize`
|
||||
return this.getEndpointURL('initialize')
|
||||
}
|
||||
|
||||
public getNonceEndpoint(): string {
|
||||
return `${this.url}${apiPath}/nonce`
|
||||
//return `${this.url}${apiPath}/nonce`
|
||||
return this.getEndpointURL('nonce')
|
||||
}
|
||||
|
||||
public getConsumeEndpointPath(): string {
|
||||
@ -304,27 +342,46 @@ export class Provider extends Instantiable {
|
||||
}
|
||||
|
||||
public getEncryptEndpoint(): string {
|
||||
return `${this.url}${apiPath}/encrypt`
|
||||
//return `${this.url}${apiPath}/encrypt`
|
||||
return this.getEndpointURL('encrypt')
|
||||
}
|
||||
|
||||
public getFileinfoEndpoint(): string {
|
||||
return `${this.url}${apiPath}/fileinfo`
|
||||
//return `${this.url}${apiPath}/fileinfo`
|
||||
return this.getEndpointURL('fileinfo')
|
||||
}
|
||||
|
||||
public getPublishEndpoint(): string {
|
||||
return `${this.url}${apiPath}/publish`
|
||||
}
|
||||
|
||||
public getComputeEndpointPath(): string {
|
||||
return `${apiPath}/compute`
|
||||
// public getComputeEndpointPath(): string {
|
||||
// return `${apiPath}/compute`
|
||||
// }
|
||||
|
||||
// public getComputeEndpoint(): string {
|
||||
// return `${this.url}` + this.getComputeEndpointPath()
|
||||
// }
|
||||
|
||||
public getComputeStatusJob(): string {
|
||||
return this.getEndpointURL('computeStatus')
|
||||
}
|
||||
|
||||
public getComputeEndpoint(): string {
|
||||
return `${this.url}` + this.getComputeEndpointPath()
|
||||
public getStartComputeJob(): string {
|
||||
return this.getEndpointURL('computeStart')
|
||||
}
|
||||
|
||||
public getStopComputeJob(): string {
|
||||
return this.getEndpointURL('computeStop')
|
||||
}
|
||||
|
||||
public getDeleteComputeJob(): string {
|
||||
return this.getEndpointURL('computeDelete')
|
||||
}
|
||||
|
||||
public getDownloadEndpoint(): string {
|
||||
return `${this.url}${apiPath}/download`
|
||||
//return `${this.url}${apiPath}/download`
|
||||
return this.getEndpointURL('download')
|
||||
}
|
||||
|
||||
/** Check for a valid provider at URL
|
||||
|
Loading…
x
Reference in New Issue
Block a user