Skip to content

Commit

Permalink
updating from main
Browse files Browse the repository at this point in the history
  • Loading branch information
josepablofm78 committed Nov 30, 2022
2 parents 5077141 + 1bedb70 commit fa3ee52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v0.4.3](https://github.com/nevermined-io/node/compare/v0.4.2...v0.4.3)

> 25 November 2022
- Fix filename when downloading [`#56`](https://github.com/nevermined-io/node/pull/56)
- get filename from ddo by default if defined [`f1f9356`](https://github.com/nevermined-io/node/commit/f1f9356819d53a9a5c61414eeffaa25536f3747f)
- Automated CHANGELOG.md update [`a785b3a`](https://github.com/nevermined-io/node/commit/a785b3a46ab260348ff7b2aa60a82d7aa4b7a557)

#### [v0.4.2](https://github.com/nevermined-io/node/compare/v0.4.1...v0.4.2)

> 22 November 2022
Expand Down
20 changes: 15 additions & 5 deletions src/shared/nevermined/nvm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export class NeverminedService {
return this.config.nvm().web3ProviderUri;
}

async getAssetUrl(did: string, index: number): Promise<{ url: string; content_type: string; dtp: boolean }> {
async getAssetUrl(
did: string,
index: number
): Promise<{ url: string; content_type: string; dtp: boolean; name?: string }> {
// get url for DID
let asset: DDO;
try {
Expand All @@ -59,14 +62,15 @@ export class NeverminedService {
const service = asset.findServiceByType('metadata');
const file_attributes = service.attributes.main.files[index];
const content_type = file_attributes.contentType;
const name = file_attributes.name;
const auth_method = asset.findServiceByType('authorization').service || 'RSAES-OAEP';
if (auth_method === 'RSAES-OAEP') {
const filelist = JSON.parse(
await decrypt(this.config.cryptoConfig(), service.attributes.encryptedFiles, 'PSK-RSA')
);
// download url or what?
const url: string = filelist[index].url;
return { url, content_type, dtp: this.isDTP(service.attributes.main) };
return { url, content_type, dtp: this.isDTP(service.attributes.main), name };
}
Logger.error(`Auth METHOD wasn't RSAES-OAEP`);
throw new BadRequestException();
Expand All @@ -76,7 +80,7 @@ export class NeverminedService {
Logger.debug(`Downloading asset from ${did} index ${index}`);
try {
// eslint-disable-next-line prefer-const
let { url, content_type, dtp } = await this.getAssetUrl(did, index);
let { url, content_type, dtp, name } = await this.getAssetUrl(did, index);
if (!url) {
Logger.error(`URL for did ${did} not found`);
throw new NotFoundException(`URL for did ${did} not found`);
Expand All @@ -86,8 +90,14 @@ export class NeverminedService {
}
Logger.debug(`Serving URL ${url}`);

const param = url.split('/').slice(-1)[0];
const filename = param.split('?')[0];
// If filename is on the ddo we will use that by default
let filename: string;
if (name) {
filename = name;
} else {
const param = url.split('/').slice(-1)[0];
filename = param.split('?')[0];
}

let response;

Expand Down

0 comments on commit fa3ee52

Please sign in to comment.