Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared files - double file download #6

Open
howkymike opened this issue Dec 2, 2022 · 0 comments
Open

Shared files - double file download #6

howkymike opened this issue Dec 2, 2022 · 0 comments

Comments

@howkymike
Copy link

howkymike commented Dec 2, 2022

Bug description

MNT-20685 commit made by @antoniojfelix introduced a bug, where a file is downloaded two times ( firstly to JS, secondly to client).
It creates 2x bigger server load and a client have to wait 2x longer. It is especially visible on the bigger files.

Proposed fix

As a fix, in the Pdfjs.js file in the downloadIfLoggedIn() function I propose to check if url contanis the "alfresco-noauth" and for the logged in validation, "/touch" API can be used.
Sample code:

downloadIfLoggedIn : function PdfJs_downloadIfLoggedIn(url)
{
      // check if site is shared
      // if yes, always download, no matter of the login state
      if(url.includes("/alfresco-noauth/"))
      {
      window.open(url, "_blank");
      return;
      }
      var request = new XMLHttpRequest();
      request.onreadystatechange = function() {
          if (this.status === 401)
          {
              // user is logged out, reload should move to login page
              window.location.reload();
          }
          else if (this.readyState == 4 && this.status == 200) {
              window.open(url, "_blank");
          }
      };
      
      // check if user has been logged out
      request.open("GET", Alfresco.constants.PROXY_URI + "touch", true);
      request.send();
}

Using the code above, there might be a problem with a 301 redirect and CORS protection (i.e. when using external auth).

Affected versions

Alfresco 7.2. and onwards.

@howkymike howkymike changed the title Shared files - double fiel download Shared files - double file download Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant