Skip to content

Commit

Permalink
get filename from ddo by default if defined
Browse files Browse the repository at this point in the history
- bump to version 0.4.3
  • Loading branch information
r-marques committed Nov 25, 2022
1 parent a785b3a commit f1f9356
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-ts",
"version": "0.4.2",
"version": "0.4.3",
"description": "Nevermined Node",
"main": "main.ts",
"scripts": {
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 f1f9356

Please sign in to comment.