ibrod83 / nodejs-file-downloader

129 stars 23 forks source link

BUG, filePath in win11 #65

Closed gowy222 closed 3 months ago

gowy222 commented 4 months ago
set config directory = D:\mycode\packages\wy-test\lib\tmp\52694bbd-1523-493f-87d7-2e819812a544

and download result filePath:
D:\mycode\packages\wy-test\lib\tmp\52694bbd-1523-493f-87d7-2e819812a544/ppocrv4.png

as can see in winodws system the result filePath had /ppocrv4.png but shouda be \ppocrv4.png

gowy222 commented 4 months ago

should add some fun to fix it before return filePath like:

function fix_path_to_local_env(inputPath) {
  if (typeof inputPath !== 'string' || inputPath.length === 0) {
    return false;
  }

  try {
    let normalizedPath = path.normalize(inputPath);
    let currentOS = process.platform;

    if (currentOS === 'win32') {
      normalizedPath = normalizedPath.split(path.posix.sep).join(path.win32.sep);
    } else {
      normalizedPath = normalizedPath.split(path.win32.sep).join(path.posix.sep);
    }

    return normalizedPath;
  } catch (error) {
    return false;
  }
}
gowy222 commented 4 months ago

the bug code issued here :

https://github.com/ibrod83/nodejs-file-downloader/blob/master/Download.js#L131 https://github.com/ibrod83/nodejs-file-downloader/blob/master/Download.js#L225


    async _shouldSkipRequest() {        
        if (this.config.fileName && this.config.skipExistingFileName) {
            if (await exists(this.config.directory + '/' + this.config.fileName)) {  
                return true
            }
        }
        return false
    }
   async _shouldSkipSaving(originalFileName) {
        if (this.config.skipExistingFileName && await exists(this.config.directory + '/' + originalFileName)) {
            return true;
        }
        return false;
    }

see, shoud NOT use + '/', need use path.join()

ibrod83 commented 3 months ago

Thank you, fixed