fetch-vcr icon indicating copy to clipboard operation
fetch-vcr copied to clipboard

use hash for long filenames

Open paulmars opened this issue 6 years ago • 3 comments

I don't expect you to merge this, there are no tests. But I wanted to propose a solution to a problem.

I was download some URLs that are longer than the filenames my system allows. Which prevents the caching from being saved.

Let me know if I'm not being clear.

paulmars avatar Aug 13 '18 17:08 paulmars

Similar to this

https://github.com/thoughtbot/paperclip/issues/1246#issuecomment-18378975

paulmars avatar Aug 13 '18 17:08 paulmars

I've also run into this issue using fetch-vcr!

What might be simpler than modifying the buildHash method is to alter the buildFilenamePrefix to simply truncate overly-long filenames like so:

var maxFilenameLength = 255

function buildFilenamePrefix(url, args, hash, suffixLength) {
  args = args || { }
  url = escape(url).replace(/\//g, '_')
  var method = args.method || 'GET' 
  method = method.toUpperCase()
  var filename =  url + '_' + method + '_' + hash
  var totalLength = filename.length + suffixLength
  return totalLength > maxFilenameLength
    ? filename.slice(0, maxFilenameLength - suffixLength)
    : filename
}

Max filename length is capped by every OS I know at 255. Let me know what you think!

the-jackalope avatar Nov 30 '18 20:11 the-jackalope

https://github.com/philschatz/fetch-vcr/pull/32 I set up this PR to address the issue.

boxman0617 avatar Jan 09 '19 20:01 boxman0617