Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkURL interface #542

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ before_script:
- export AQUARIUS_URI="http://172.15.0.5:5000"
- export DEPLOY_CONTRACTS="true"
- export CONTRACTS_VERSION=v0.5.7
- export PROVIDER_VERSION=latest
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd ..
- ./scripts/waitforcontracts.sh
Expand Down
20 changes: 14 additions & 6 deletions src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import { DDO } from '../ddo/DDO'

const apiPath = '/api/v1/services'

export interface urlDetails {
alexcos20 marked this conversation as resolved.
Show resolved Hide resolved
valid: boolean
contentLength?: string
contentType?: string
}
/**
* Provides an interface for provider service.
* Provider service is the technical component executed
Expand Down Expand Up @@ -73,20 +78,23 @@ export class Provider extends Instantiable {
}
}

public async checkURL(url: string): Promise<Record<string, string>> {
alexcos20 marked this conversation as resolved.
Show resolved Hide resolved
/** Get URL details (if possible)
* @param {String} url
* @return {Promise<urlDetails>} urlDetails
*/
public async checkURL(url: string): Promise<urlDetails> {
const args = { url }
try {
const response = await this.ocean.utils.fetch.post(
this.getCheckURLEndpoint(),
decodeURI(JSON.stringify(args))
)

const result = await response.json()

return result.result
const result: urlDetails = await response.json()
return result
} catch (e) {
this.logger.error(e)
throw new Error('HTTP request failed')
const result: urlDetails = { valid: false }
return result
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/integration/Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ describe('Provider tests', () => {
it('Check a valid URL', async () => {
const url = 'https://s3.amazonaws.com/testfiles.oceanprotocol.com/info.0.json'
const response = await ocean.provider.checkURL(url)
assert(response.valid === true)
assert(response.contentLength === '1161')
assert(response.contentType === 'application/json')
})
it('Check a invalid URL', async () => {
const url = 'https://s3.amazonaws.com/testfiles.oceanprotocol.com/nosuchfile'
const response = await ocean.provider.checkURL(url)
assert(response.valid === false)
})
})