Skip to content

Commit

Permalink
update also path, have default, use index for name as well, if not pr…
Browse files Browse the repository at this point in the history
…ovided a filename
  • Loading branch information
paulo-ocean committed Jul 3, 2024
1 parent 12458f2 commit 412bc6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ export class Commands {
this.signer
);
try {
const { filename } = await downloadFile(urlDownloadUrl, args[2]);
console.log("File downloaded successfully:", args[2] + "/" + filename);
const path = args[2] ? args[2] : '.';
const { filename } = await downloadFile(urlDownloadUrl, path);
console.log("File downloaded successfully:", path + "/" + filename);
} catch (e) {
console.log(`Download url dataset failed: ${e}`);
}
Expand Down Expand Up @@ -609,16 +610,19 @@ export class Commands {
}

public async downloadJobResults(args: string[]) {

const jobResult = await ProviderInstance.getComputeResultUrl(
this.providerUrl,
this.signer,
args[1],
parseInt(args[2])
);
console.log("jobResult ", jobResult);

try {
const { filename } = await downloadFile(jobResult, args[3]);
console.log("File downloaded successfully:", args[3] + "/" + filename);
const path = args[3] ? args[3] : '.';
const { filename } = await downloadFile(jobResult, path, parseInt(args[2]));
console.log("File downloaded successfully:", path + "/" + filename);
} catch (e) {
console.log(`Download url dataset failed: ${e}`);
}
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export async function downloadFile(
if (!response.ok) {
throw new Error("Response error.");
}
const defaultName = index && index > -1 ? `file_${index}.out` : 'file.out'

const defaultName = !isNaN(index) && index > -1 ? `file_${index}.out` : 'file.out'
let filename: string

try {
// try to get it from headers
filename = response.headers
Expand Down

0 comments on commit 412bc6a

Please sign in to comment.