nas-download-manager icon indicating copy to clipboard operation
nas-download-manager copied to clipboard

"open with Synology Download Manager" should be an option in the browser's "what do you want to open this file/link with" popup

Open ceekei opened this issue 7 years ago • 6 comments

Hi!

Great extension, the update to FF57 brought me here. Your Extension has many more cool features than the others I have used but I miss one thing, which i cannot find here as a feature request.

When there is a download with no Download Link which is accessible with right click, such as a download started through a script the browser opens a dialouge-Box what to do with the file. Here would be great to have the option "Download with synology download Manager".

Thanks in advance.

ceekei avatar Nov 15 '17 10:11 ceekei

Hey there, glad you like the extension! The new restrictions placed on extensions in Firefox 57+ have dropped a number of features, and based on my searching the documentation, this one appears to be included. I agree, it's quite inconvenient -- the only advice I can give you when sites do this is to accept the download, then open the Downloads view in Firefox, right-click the download and Copy Download Link, at which point you can paste it into the extension (after clicking the + button).

This is a feature I would like to have, so I'm going to leave this issue open indefinitely in case Mozilla introduces a way for me to implement it.

seansfkelley avatar Nov 16 '17 00:11 seansfkelley

Hello seansfkelley! I am really glad I found your addon as you seem to be the only active developer for a Synology addon. During my research on this topic I stumbled upon an approach to integrate an external download manager (https://addons.mozilla.org/en-US/firefox/addon/ugetintegration/) by passing the download URL to a program. Would it be possible to adapt this in conjunction with something like SynoGet, which passes a download URL to the Synology DLM? You can get SynoGet and the source here: http://www.synology-forum.de/showthread.html?3616-SynoGet-Download-via-Kommandozeile-hinzuf%C3%BCgen/page4 (post by BjoernWeber at 16.05.2010 08:39) Personally I would use this to redirect certain file types to the NAS. But being able to redirect just every download to the NAS with an on/off switch would be really great already. Thanks!

therealransom avatar Dec 22 '17 16:12 therealransom

Hm, interesting, it looks like uGet Integration uses a pair of rather invasive APIs to get the job done, but between them most use-cases are probably covered:

  • downloads.onCreated (used here) which appears to fire when the user okays the download dialog and the download begins (which is too late for good UX, I think).
  • webRequest.onHeadersReceived (used here) which intercepts every (!) request and checks if it's suitable for downloading, then fires off a request to do so and cancels the original. This would probably work for Synology Download Manager, but it's pretty invasive, has the potential to slow everything down and it'd be a good chunk of work to implement. It would prevent the download dialog from ever appearing though, so it ought to be more transparent and should work for magnet links as well. (EDIT: The docs say that cancel cannot be set in this handler -- so will this even provide nice UX or will we end up with doubled downloads?)

seansfkelley avatar Dec 22 '17 16:12 seansfkelley

The following extension does this without being invasive to all requests: https://addons.mozilla.org/en-US/firefox/addon/transmitter-for-transmission/

codebase:

  • https://github.com/myfreeweb/transmitter

more specifically:

RowanKaag avatar May 27 '18 23:05 RowanKaag

Hm, interesting, thanks for the links.

It looks like it only supports the magnet protocol (due to limitations in registerProtocolHandler and protocol_handlers), not .torrent files served over HTTP(S). It does it by rewriting magnet links to use the nonce transmitter.web-extension host and then registering an onBeforeRequest handler scoped down to just that nonce host. onBeforeRequest is also capable of intercepting every request, but the clever protocol_handlers trick prevents it from needing to do so.

More details on this workaround available at StackOverflow. The complete list of legal protocol_handlers might also be useful. The tracking bug on Bugzilla has a lot of detail, but seems to be focused on improving the existing implementation rather than adding support for extensions to directly intercept certain requests or register themselves with the download window.

seansfkelley avatar May 30 '18 18:05 seansfkelley

I'm working on a similar extension but for aria2c. For the download API I use the following code to get the *.torrent file when it was downloaded and send its content to the aria2c rpc service.

function handleChanged(delta) {
  const { endTime, state, id } = delta;
  if (!endTime || !state) {
    return;
  }

  if (state.current === 'complete') {
    console.log(`Download ${delta.id} has completed.`);

    // workaround: search by id not works well in incognito
    chrome.downloads.search({ orderBy: ['-startTime'] }, (items) => {
      const [target] = items.filter((itm) => itm.endTime === endTime.current && itm.id === id);
      const {
        filename,
        mime,
      } = target;
      if (!mime.includes('application/x-bittorrent')
        && !filename.endsWith('.torrent')) {
        // not torrent file
        return;
      }

      const url = `file://${filename}`;
      const xhr = new XMLHttpRequest();
      // Load the data directly as a Blob.
      xhr.responseType = 'blob';
      xhr.onload = () => {
        const reader = new FileReader();
        reader.readAsDataURL(xhr.response);
        reader.onloadend = () => {
          const base64data = reader.result;

          jrpc.call('aria2.addTorrent', [
            ARIA2_TOKEN,
            base64data.replace(/.*:.*;base64,(.*)/, (p1, p2) => p2),
          ]).then((res) => {
            // success, remove the torrent file
            chrome.downloads.removeFile(id);
          }).catch((err) => {
            console.log(err);
          });
        };
      };

      xhr.open('GET', url);
      xhr.send();
    });
  }
}

chrome.downloads.onChanged.addListener(handleChanged);

larvata avatar Jul 11 '21 12:07 larvata