ngx-lightbox icon indicating copy to clipboard operation
ngx-lightbox copied to clipboard

Feature Request: Allow download url to be overridden.

Open h5aaimtron opened this issue 2 years ago • 4 comments

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 avatar Mar 09 '22 02:03 h5aaimtron

@themyth92 Pull Request

h5aaimtron avatar Mar 09 '22 03:03 h5aaimtron

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'.

inaitana avatar May 13 '22 14:05 inaitana

@themyth92

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

downloadUrl?: string

The rest of the code should already work.

h5aaimtron avatar May 13 '22 15:05 h5aaimtron

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

AXeL-dev avatar Jul 14 '22 14:07 AXeL-dev