noxify / gridsome-plugin-remote-image

simple plugin to download remote images in gridsome
MIT License
14 stars 16 forks source link

Feat - Cache & Original Filename #14

Closed travis-r6s closed 4 years ago

travis-r6s commented 4 years ago

This PR makes quite a few changes to the getRemoteImage function, to attempt to solve a couple of issues, namely #12 #2

I tried to solve both cases presented in #2, by simply parsing the URL to remove search params, and if the URL has no image extension then it will perform a HEAD request to get the content-type of the image source. By trying to guess the image ext before download, we can add a cache option as we can create the target file path beforehand.

It adds a couple of options:

options: {
    cache: false // default = true
    original: true //default = false
}
noxify commented 4 years ago

thanks @thetre97 for the PR. Looks good so far. The docs are prepared and the readme is updated.

I have one question. Based on the discussion in #2, how can we ensure that we don't overwrite an image even when original is set to true.

Example:

Record one contains the remote image https://www.example.com/path1/sub1/image.jpg. Record two contains the remote image https://www.example.com/path2/sub2/image.jpg.

Correct me if I'm wrong, but record two will overwrite the image from record one in the current implementation.

travis-r6s commented 4 years ago

When original is set to true, it uses the url path to the image as a folder structure, so it will download the images like so:

/src/assets/remoteImages/path1/sub/image.jpg
/src/assets/remoteImages/path2/sub2/image.jpg

So they shouldn't overwrite each other... See https://github.com/noxify/gridsome-plugin-remote-image/pull/14/files#diff-9fd137e3cea1d73377052301c6fea3bfR160 (dir is the image url path /path2/sub2 etc)