universalviewer icon indicating copy to clipboard operation
universalviewer copied to clipboard

A way to disable `wholeImageHighRes`, `wholeImagesHighRes`, and `currentViewAsJpg`

Open kirkkwang opened this issue 3 years ago • 1 comments

UV version: v3.1.4

I'm submitting a:

  1. As a developer, I want an easy way to disable wholeImageHighRes, wholeImagesHighRes, and currentViewAsJpg so that the high resolution image is not available for download through the UV.

  2. As a developer, I want an easy way to change the way a jpg downloads so that the file does not open a new tab and reveal the URL and instead downloads directly.

  3. As a developer, I want an easy way to change the filename of the download so that instead of default.jpg, it would be the actual <filename>.jpg

  4. As a developer, I want the confinedImageSize property to respect not just width but also height so that the maximum "long edge" can be set.

Currently, there is no easy way of changing the above use cases except to delete/comment out instances of wholeImageHighRes, wholeImagesHighRes, and currentViewAsJpg.

Related code:

As mentioned earlier, a developer would comment out instances of wholeImageHighRes, wholeImagesHighRes, and currentViewAsJpg to remove those as options. To force a download of the image, something like this would need to be added:

case DownloadOption_1.DownloadOption.WHOLE_IMAGE_LOW_RES:
  var imageUri = that.extension.getConfinedImageUri(canvas, that.options.confinedImageSize);
  if (imageUri) {
      // UV override begins
      // window.open(imageUri);
      var filename = canvas.__jsonld.label.split(".").slice(0, -1).join(".") + ".jpg"
      var link = document.createElement('a');
      link.href = imageUri;
      link.download = filename;
      link.click();
      // UV override ends

As for the confinedImageSize our solution was something like this for the label

if (this.isDownloadOptionAvailable(DownloadOption_1.DownloadOption.WHOLE_IMAGE_LOW_RES)) {
    var $input = this.$wholeImageLowResAsJpgButton.find('input');
    var $label = this.$wholeImageLowResAsJpgButton.find('label');
    var size = this.extension.getConfinedImageDimensions(canvas, this.options.confinedImageSize);
    // UV override begins
    var maxEdge = this.options.confinedImageSize;
    var dimensions = this.getCanvasComputedDimensions(this.extension.helper.getCurrentCanvas());
    var originalWidth = dimensions.width;
    var originalHeight = dimensions.height;
    var reductionRatio = originalWidth <= maxEdge && originalHeight <= maxEdge ?
        1 : maxEdge / Math.max(originalHeight, originalWidth);
    size.width = Math.round(originalWidth * reductionRatio);
    size.height = Math.round(originalHeight * reductionRatio);
    // UV override ends

And for the download

Extension.prototype.getConfinedImageUri = function (canvas, width) {
    var baseUri = this.getImageBaseUri(canvas);
    // {baseuri}/{id}/{region}/{size}/{rotation}/{quality}.jpg
    var id = this.getImageId(canvas);
    if (!id) {
        return null;
    }
    var region = 'full';
    // UV override begins
    var maxEdge = width;
    var originalWidth = canvas.getWidth();
    var originalHeight = canvas.getHeight();
    var reductionRatio = originalWidth <= maxEdge && originalHeight <= maxEdge ?
        1 : maxEdge / Math.max(originalHeight, originalWidth);
    var dimensionsWidth = Math.round(originalWidth * reductionRatio);
    var dimensionsHeight = Math.round(originalHeight * reductionRatio);
    var size = dimensionsWidth + ',' + dimensionsHeight;
    // UV override ends

Other information: This was a use case where a stakeholder wanted to deter public downloads of the full resolution images and limit it down to 600px long edge instead. And to further obstruct the user from gaining access to the full resolution, the stakeholder wanted the download to initiate immediately instead of opening another tab and revealing the URL. There was no easy way to accomplish this in the uv-config.json so the uv.js had to be modified.

kirkkwang avatar Aug 31 '22 05:08 kirkkwang

  1. Agreed, this should be overridable in config
  2. In order to allow direct download via right click, we'd need to refactor download links to anchor tags using the html5 download attribute instead of buttons. However, this wouldn't work cross origin: https://stackoverflow.com/a/28468261 which is a necessity for the UV as it can be hosted anywhere.
  3. We could potentially add a ?download querystring parameter to URLs in the downloads panel so that a server-side solution can then download a renamed file.
  4. Agreed that confinedImageSize should use the longest edge

edsilv avatar Sep 21 '22 16:09 edsilv

As discussed on the June 21 Steering Committee group: would anyone object if we close this ticket and open three new ones to separate the independent issues raised here:

1.) Add configuration settings to disable wholeImageHighRes, wholeImagesHighRes, and currentViewAsJpg so that the high resolution image is not available for download through the UV.

2.) Add configuration setting to add additional query parameters to download links in order to drive server-side functionality. I wouldn't want to tackle this without a specific use case, though, since I think the configuration would need to be flexible enough to accommodate different server-side scenarios, and without knowing what those are, we might go down the wrong road.

3.) Change behavior of confinedImageSize to respect both height and width.

I think on this list, issues 1 and 3 could get attention sooner -- issue 2 probably needs deeper discussion and might or might not meet the original need.

I don't think there's much we can do about the "download without opening a new tab" issue due to browser limitations, but happy to open a separate issue for that as well if the conversation is worth continuing.

demiankatz avatar Jun 21 '23 16:06 demiankatz

Since no one has objected in a month's time (and I have a thumbs-up from @kirkkwang), I have opened #926, #927 and #928 and am closing this issue. I refer back to this issue from the other three, so the additional context from here will still be readily accessible. Please feel free to open additional issues if you feel that any key details from this conversation are not reflected in the new issues.

demiankatz avatar Jul 19 '23 16:07 demiankatz

@demiankatz much appreciated!

kirkkwang avatar Jul 19 '23 17:07 kirkkwang