fix: serve quartz with clean URL support and regenerate site
- Add serve.py to resolve clean Quartz URLs to .html files - Regenerate Quartz site with correct baseUrl http://100.118.5.51:9120 - 196 HTML files emitted; all internal links now resolve
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
# Quartz
|
||||
A module to interface with Transmission's RPC
|
||||
|
||||
# How to install
|
||||
`npm install quartz`
|
||||
|
||||
# Functions
|
||||
|
||||
## quartz.connect(options, callback)
|
||||
var quartz = require('quartz');
|
||||
|
||||
quartz.connect({
|
||||
url: "http://localhost:9091/transmission/rpc"
|
||||
, auth_required: false
|
||||
, username: "admin"
|
||||
, password: "password"
|
||||
}, function(err) {
|
||||
if (err) { console.log(err); } else {
|
||||
// Connected!
|
||||
}
|
||||
});
|
||||
|
||||
## quartz.query(method, args, callback)
|
||||
// after connect
|
||||
|
||||
quartz.query(
|
||||
'torrent-get',
|
||||
{fields: ['id', 'name']},
|
||||
function(err, res, body) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
// do stuff
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
# Features
|
||||
* Auth based login support
|
||||
|
||||
# Todo
|
||||
* Functions for each RPC call
|
||||
|
||||
# Author
|
||||
* Robin Duckett <[robin.duckett@gmail.com](mailto:robin.duckett@gmail.com)>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "quartz",
|
||||
"description": "A module to interface node with transmission-daemon",
|
||||
"author": "Robin Duckett <robin.duckett@gmail.com>",
|
||||
"version": "0.0.1",
|
||||
"keywords": ["transmission", "quartz", "transmission-daemon"],
|
||||
"dependencies": {
|
||||
"request": "*",
|
||||
"underscore": "*"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/robinduckett/quartz"
|
||||
},
|
||||
"bugs": {
|
||||
"email": "robin.duckett+quartz@gmail.com",
|
||||
"url": "http://github.com/robinduckett/quartz/issues"
|
||||
},
|
||||
"main": "./quartz.js",
|
||||
"engine": "node 0.6.0"
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
var request = require('request')
|
||||
, _ = require('underscore');
|
||||
|
||||
function Quartz() {}
|
||||
|
||||
Quartz.prototype.connect = function(options, callback) {
|
||||
var defaults = {
|
||||
url: "http://localhost:9091/transmission/rpc"
|
||||
, auth_required: false
|
||||
, username: "admin"
|
||||
, password: "password"
|
||||
};
|
||||
|
||||
var opts = _.extend(defaults, options);
|
||||
|
||||
this.url = opts.url;
|
||||
this.auth_required = opts.auth_required;
|
||||
this.username = opts.username;
|
||||
this.password = opts.password;
|
||||
|
||||
// connect and get the authorisation key
|
||||
this.query("torrent-get", {
|
||||
fields: [
|
||||
"id"
|
||||
, "name"
|
||||
, "status"
|
||||
]
|
||||
}, function(err, res, body) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
if (body.result == "success") {
|
||||
callback(null);
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Quartz.prototype.query = function(method, args, callback) {
|
||||
var self = this;
|
||||
|
||||
var data = {
|
||||
'method': method,
|
||||
'arguments': args
|
||||
};
|
||||
|
||||
var json = JSON.stringify(data);
|
||||
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'x-transmission-session-id': this.session_id
|
||||
};
|
||||
|
||||
if (this.auth_required) {
|
||||
var auth = new Buffer(this.username + this.password).toString('base64');
|
||||
headers['Authorization'] = 'Basic ' + auth;
|
||||
}
|
||||
|
||||
var req = {uri: this.url, method: 'POST', body: json, headers: headers};
|
||||
|
||||
request(req, function(err, res, body) {
|
||||
if (res.headers['x-transmission-session-id']) self.session_id = res.headers['x-transmission-session-id'];
|
||||
|
||||
switch (res.statusCode) {
|
||||
case 409:
|
||||
self.query(method, args, callback);
|
||||
break;
|
||||
case 401:
|
||||
throw new Error("Invalid username / password");
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
var json_body = JSON.parse(body);
|
||||
} catch (e) {
|
||||
callback.call(this, e, null, null);
|
||||
}
|
||||
|
||||
if (typeof json_body != "undefined") {
|
||||
callback.call(this, err, res, json_body);
|
||||
} else {
|
||||
callback.call(this, "unable to parse JSON", null, null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = new Quartz();
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
var quartz = require('./quartz');
|
||||
|
||||
quartz.connect({
|
||||
auth_required: true
|
||||
}, function(err) {
|
||||
if (!err) {
|
||||
quartz.query('torrent-get', {
|
||||
fields: [
|
||||
"id"
|
||||
, "name"
|
||||
, "status"
|
||||
]
|
||||
}, function(err, res, body) {
|
||||
if (err) {
|
||||
console.log('Error: ' + err);
|
||||
} else {
|
||||
console.log(require('util').inspect(body, false, 50));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Error: ' + err);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user