Giter VIP home page Giter VIP logo

Comments (6)

seansfkelley avatar seansfkelley commented on August 23, 2024 1

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.

from nas-download-manager.

seansfkelley avatar seansfkelley commented on August 23, 2024

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.

from nas-download-manager.

therealransom avatar therealransom commented on August 23, 2024

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!

from nas-download-manager.

seansfkelley avatar seansfkelley commented on August 23, 2024

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?)

from nas-download-manager.

RowanKaag avatar RowanKaag commented on August 23, 2024

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

codebase:

more specifically:

from nas-download-manager.

larvata avatar larvata commented on August 23, 2024

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);

from nas-download-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.