Code Monkey home page Code Monkey logo

jsondispatch's Introduction

Table of Contents

  1. Json Dispatch
    1. Use Cases
      1. Send file to aria2 and set download dir based on category
    2. Install & Use
      1. Server
      2. Browser extension
    3. Develop
      1. Files Layout
    4. License

Json Dispatch

Server program written in python that accepts HTTP POST requests with a JSON payload and forwards the request to another program, after transforming it in a configurable way. Quite generic, but that's the goal. See 1.1 for concrete examples.

Python 3.6 supported only, although other Python 3.X versions should work too.

Also provides a Firefox and Chrome extension that talks to the server and allows you to right click on a URL/link in your browser and "send it to" the server.

Use Cases

Send file to aria2 and set download dir based on category

Config file /etc/jsondispatch/jsondispatch.conf:

cors:
  domain: '*'

commands:
  aria2:
    url: http://localhost:6800/jsonrpc
    rpc_secret: mYs3Cr3t

triggers:
  download_program_uri:
    - command: aria2
      method: addUri
      arguments:
        url: {url}
        dir: /srv/backups/programs

JSON payload to send to the server with URL ending with /trigger/download_program_uri with POST request:

{
    "url": "magnet:?xt=urn:btih:204a1789dd04e4d8f5a4e098e8f777794888f4ad&dn=archlinux-2017.12.01-x86_64.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce"
}

When sending the above POST request, jsondispatch will call the addUri RPC method of aria2 with the given magnet URL and the hardcoded dir argument.

Or just use the browser extension which does this for you with a right click on a magnet URL (or any link for that matter).

Install & Use

Server

To install the server, clone this repo, cd in the repo and run:

pip install -e "."

Create a configuration file in /etc/jsondispatch/jsondispatch.conf (by default, --config option lets you setup a custom file location). See 1.1 for example configurations.

To run the server, cd in the repo and run:

python . 

You can change the default port and config file location, give the --help argument for detailed instructions.

Browser extension

For Firefox, go to about:debugging and click on Load Temporary Add-On. Browse to the browserextension/ folder in this repo and select the manifest.json file. Now that the addon is added, go to the addons settings page about:addons and fill-in the server URL.

If you're running the server locally with default port, then the URL is http://127.0.0.1:8850.

For Chrome, go to chrome://extensions/, enable Developer mode, click on Load unpacked extension. Browse to the firefox/ folder in this repo and click on open. Now that the addon is added, click on the addon's option button and fill-in the server URL.

Now you can just right click on a link and go in the submenu Send to Json Dispatch, then choose one of the options which correspond to the configured triggers. Of course, first make sure you installed and started the server as explained in 1.2.1.

Develop

pip install -e ".[dev,test]"

Files Layout

License

The icon was taken from https://feathericons.com/, it's under MIT License.

jsondispatch's People

Contributors

dependabot[bot] avatar ibizaman avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.