davidmatas / syno

Simple Node.js wrapper and CLI for Synology DSM REST API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syno

Simple Node.js wrapper (browser included) and CLI for Synology DSM REST API.

Built with Grunt Build Status npm version Dependency Status devDependency Status Synology Development Tool

See Synology Development Tool.

Installation

Just install the module using npm.

$ npm install syno

If you want to save it as a dependency, just add the --save option.

$ npm install syno --save

If you want to install with the CLI executable, just add the --global option.

$ npm install syno --global

Syno API

This is a simple presentation of the syno API and its methods. To get more information (parameters, response data, ...) use the PDF documents (see in the wiki).

Javascript wrapper

var Syno = require('syno');
var syno = new Syno({
    // Requests protocol : 'http' or 'https' (default: http)
    protocol: 'https',
    // DSM host : ip, domain name (default: localhost)
    host: 'localhost',
    // DSM port : port number (default: 5000)
    port: '5001',
    // DSM User account (required)
    account: 'my_username',
    // DSM User password (required)
    passwd: 'my_password'
});

This is how to use an API on the syno object

syno.api.method(params, callback);

All arguments are optional by default :

  • params : object hash with request parameters
  • callback : function called with 2 arguments (error, data)

The data arguments passed to the callback is an object hash, holding the response data. (see API documents)

Both the params and callback are optional, so you can call any method these ways :

// Both params and callback
syno.api.method(params, callback);
// Only params parameter
syno.api.method(params);
// Only callback parameter
syno.api.method(callback);
// No parameter
syno.api.method();

N.B : If the params parameter is not passed, but the method expects required parameters, an Error will be thrown.

Examples

// File Station API - Provide File Station information
syno.fs.getFileStationInfo(callback);
// File Station API - Enumerate files in a given folder
syno.fs.listFiles({'folder_path':'/path/to/folder'}, callback);
// Download Station API - List download tasks
syno.dl.listFiles({'limit':5, 'offset':10}, callback);
// Download Station API - Create a download task
syno.dl.createTask({'uri':'https://link'}, callback);
// Audio Station API - Search a song
syno.as.searchSong({'title':'my_title_song'}, callback);
// Video Station API - List movies
syno.vs.listMovies({'limit':5}, callback);
// Video Station DTV API - List channels
syno.dtv.listDTVChannels({'limit':5}, callback);
// Surveillance Station API - Get camera information
syno.ss.getCameraInfo({'cameraIds':4}, callback);

CLI

$ syno --help
Usage: syno [options]

  Synology Rest API Command Line

  Options:

    -h, --help           output usage information
    -V, --version        output the version number

  Commands:

    diskstationmanager|dsm [options] <method> DSM API
    filestation|fs [options] <method> DSM File Station API
    downloadstation|dl [options] <method> DSM Download Station API
    audiostation|as [options] <method> DSM Audio Station API
    videostation|vs [options] <method> DSM Video Station API
    videostationdtv|dtv [options] <method> DSM Video Station DTV API
    surveillancestation|ss [options] <method> DSM Surveillance Station API

  Examples:

    $ syno diskstationmanager|dsm getDSMInfo
    $ syno filestation|fs getFileStationInfo
    $ syno downloadstation|dl getDownloadStationInfo
    $ syno audiostation|as getAudioStationInfo
    $ syno videostation|vs getVideoStationInfo
    $ syno videostationdtv|dtv listDTVChannels --payload '{"limit":5}' --pretty
    $ syno surveillancestation|ss getSurveillanceStationInfo

Examples

# DSM API - Provide DSM information
$ syno dsm getDSMInfo --pretty
# File Station API - Provide File Station information
$ syno fs getFileStationInfo --pretty
# File Station API - Enumerate files in a given folder
$ syno fs listFiles --payload '{"folder_path":"/path/to/folder"}' --pretty
# Download Station API - List download tasks
$ syno dl listFiles --payload '{"limit":5, "offset":10}' --pretty
# Download Station API - Create a download task
$ syno dl createTask --payload '{"uri":"https://link"}'
# Audio Station API - Search a song
$ syno as searchSong --payload '{"title":"my_title_song"}' --pretty
# Video Station API - List movies
$ syno vs listMovies --payload '{"limit":5}' --pretty
# Video Station DTV API - List channels
$ syno dtv listDTVChannels --payload '{"limit":5}' --pretty
# Surveillance Station API - Get camera information
$ syno ss getCameraInfo --payload '{"cameraIds":4}' --pretty

CLI Authentication

Without a configuration file

$ syno fs getFileStationInfo --url https://user:password@localhost:5001 --pretty

With a configuration file

# Example config file, by default it should be located at:
# ~/.syno/config.yaml

url:
  protocol: https
  host: localhost
  port: 5001
  account: admin
  passwd: password
$ syno fs getFileStationInfo --pretty

More usage examples in the wiki.

Browser

Note

Be sure to disable same-origin policy in your browser.

Example

<html>
  <head>
  <script src="syno.min.js"></script>
  <script type="text/javascript">
  var Syno = require('syno.Syno');
  var syno = new Syno({
      // Requests protocol : 'http' or 'https' (default: http)
      protocol: 'https',
      // DSM host : ip, domain name (default: localhost)
      host: 'localhost',
      // DSM port : port number (default: 5000)
      port: '5001',
      // DSM User account (required)
      account: 'my_username',
      // DSM User password (required)
      passwd: 'my_password'
  });

  syno.fs.getFileStationInfo(function(error, data) {
    console.log(data)  
  });
  </script>
  </head>
<html>

Demo

A demo is available online or in the test/browser folder.

Authors

License

Copyright (c) 2016 Quentin Rousseau <contact@quent.in>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

About

Simple Node.js wrapper and CLI for Synology DSM REST API.

License:MIT License


Languages

Language:JavaScript 55.4%Language:CoffeeScript 43.2%Language:HTML 0.9%Language:Shell 0.6%