Skip to content

Commit

Permalink
feat: fetch from s3 compatible storage
Browse files Browse the repository at this point in the history
  • Loading branch information
r-marques committed Apr 13, 2023
1 parent 895835f commit 2574b60
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
24 changes: 24 additions & 0 deletions src/shared/nevermined/nvm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ export class NeverminedService {
}

response = await firstValueFrom(this.httpService.request(config))

// S3 compatible storage
} else if (url.startsWith('s3://')) {
const s3Url = new URL(url)
const bucketName = s3Url.host
const filePath = s3Url.pathname.substring(1)

const s3 = new AWS.S3({
accessKeyId: this.config.get('AWS_S3_ACCESS_KEY_ID'),
secretAccessKey: this.config.get('AWS_S3_SECRET_ACCESS_KEY'),
endpoint: this.config.get('AWS_S3_ENDPOINT'),
region: 'auto',
})

const bucketOptions = {
Bucket: bucketName,
Key: filePath,
}
const fileObject = await s3.getObject(bucketOptions).promise()
response = {
data: fileObject.Body,
}
} else {
const config: HttpModuleOptions = {
responseType: 'arraybuffer',
Expand Down Expand Up @@ -216,9 +238,11 @@ export class NeverminedService {
return new StreamableFile(contents)
} catch (e) {
if (e instanceof NotFoundException) {
console.log('not found')
Logger.error(e)
throw e
} else {
console.log('error')
Logger.error(e)
throw new InternalServerErrorException(e.toString())
}
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1362,23 +1362,23 @@
jose "^4.11.2"
passport-strategy "^1.0.0"

"@nevermined-io/sdk-dtp@0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk-dtp/-/sdk-dtp-0.4.0.tgz#1e02e89ef335badcbb3864db491e17b449f51e09"
integrity sha512-MMWQ9G7PQQZLrqvkoOttieqLMpvdSIJm+Iv5O/SR0tDAoCMxJMHrF3NtkvVs/13qf4VsmT7KwLqBJ6/MQdot3A==
"@nevermined-io/sdk-dtp@^0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk-dtp/-/sdk-dtp-0.4.4.tgz#7b6e323776ea3b1b345bad710f887ce9d24d8d6a"
integrity sha512-Tveol76noekLKRWUkQdoV3eUQIHV2qUg07wksTGc0Z5YM9sSKyzGlxX7mKHX13LOsMPQKg5GMepTIGh4aO351Q==
dependencies:
"@nevermined-io/sdk" "1.1.0"
"@nevermined-io/sdk" "1.3.3"
circomlibjs "^0.1.1"
eciesjs "^0.3.15"
ffjavascript "^0.2.55"
node-rsa "^1.1.1"
snarkjs "^0.4.26"
web3-utils "^1.7.4"

"@nevermined-io/sdk@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk/-/sdk-1.1.0.tgz#b18d63b2c17ef0508aed363a24750bbcfd1b8e87"
integrity sha512-UTT1l9VCIHVs7GM/PKnRFUHjT6KQIwH9WZ5fPQEQpeKzP4nDEmsyMOse9q2I4YtPY4O6az41EHWvfFmmljxhLw==
"@nevermined-io/sdk@1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@nevermined-io/sdk/-/sdk-1.3.3.tgz#19176b7647989b3a53112acd01c346782f302b3a"
integrity sha512-Zcber/t3AZW8qDwzMfNcdNnfJLN2vfIkWHloVUjvZgzcjpXcF+jYEY20Q1lCtOeB+mHd5FFmE9rW9nwgvdNp7Q==
dependencies:
"@nevermined-io/subgraphs" "0.5.0"
assert "^2.0.0"
Expand Down

0 comments on commit 2574b60

Please sign in to comment.