themyth92 / ngx-lightbox

Lightbox2 use with angular >= 5
MIT License
115 stars 70 forks source link

Feature Request: Allow download url to be overridden. #129

Open h5aaimtron opened 2 years ago

h5aaimtron commented 2 years ago

Right now the package attempts to pull the src passed in on the image object and trigger a save, however; this doesn't work when images are hosted on separate origins due to CORS. It would be a great feature if you can add a property, say "downloadUrl" that if populated, is used instead of the src value on download click. This allows users to proxy download when necessary while still loading the original source without a proxy.

h5aaimtron commented 2 years ago

@themyth92 Pull Request

inaitana commented 2 years ago

This pull request introduced a potential breaking change, by making downloadUrl mandatory for IAlbum.

I know it's my fault for hard typing the variable (first argument to lightbox.open) to IAlbum[] when declaring it, whereas in your example it's declared as generic, but I can't see a reason why we shouldn't, since open() actually takes an IAlbum[] as its first argument.

And I really think downloadUrl should be optional.

Code:

    const gallery: IAlbum[] = [];
    for (const file of files) {
        gallery.push({
          src: environment.static_url + file.filepath,
          caption: file.description,
          thumb: environment.static_url + file.filepath
        });
    }
    this.lightbox.open(gallery, 0);

Error:

TS2345: Argument of type '{ src: string; caption: string; thumb: string; }' is not assignable to parameter of type 'IAlbum'.
  Property 'downloadUrl' is missing in type '{ src: string; caption: string; thumb: string; }' but required in type 'IAlbum'.
h5aaimtron commented 2 years ago

@themyth92

The change to make the property in the interface optional would be:

downloadUrl?: string

The rest of the code should already work.

AXeL-dev commented 2 years ago

Pull request created: https://github.com/themyth92/ngx-lightbox/pull/136 .