oceanprotocol / ocean-cli

4 stars 5 forks source link

downloadFile should have a default filename, to avoid saving file errors #62

Closed paulo-ocean closed 1 month ago

paulo-ocean commented 2 months ago

Right now we have:

let filename: string;
    try {
        filename = response.headers
            .get("content-disposition")
            .match(/attachment;filename=(.+)/)[1];
    } catch {
        try {
            filename = url.split("/").pop();
        } catch {
            filename = `file${index}`;
        }
    }

Failing Example: In case of downloading the job results and if the node/provider is not providing content-disposition headers, we do a split of the url to get the filename: We end up with something like the following, as a filename: computeResult?consumerAddress=0x6c957a45C801035d3297d43d0Ce83a237Ec5E0d1&jobId=0x66131149ffdc8144368370622bf705ed3135a996f4908e4b7d0828a4199d80b0-4f0048b5512448e5bac8faf805cc16a3&index=0&nonce=6&signature=0xeb7184dac27f8878617d9740a73d8df20e5aa387f29f146cc53ee4aed40944371f04fd6c993d6297830435b7be297594de0e3f217c21b42f3c3f79bb340dddf71c Which will not work as a valid filename, so we need a shorter default name...