Add config field for lstu;
This commit is contained in:
parent
e15e43e885
commit
ca6dbcfbd5
@ -21,4 +21,7 @@ module.exports = {
|
||||
|
||||
// Network interface on which to run the webhook server.
|
||||
hostname: '0.0.0.0',
|
||||
|
||||
// Instance of lstu to shorten links -- keep empty to not use.
|
||||
lstu: 'https://lstu.fr'
|
||||
}
|
||||
|
12
index.js
12
index.js
@ -33,8 +33,15 @@ var app = express();
|
||||
app.use(bodyParser.json()); // for parsing application/json
|
||||
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||
|
||||
function shortenURL(url, callback) {
|
||||
request('https://lstu.fr/a', { method: 'POST', form: { lsturl: url, format: 'json' } }, function (err, res, body) {
|
||||
var shortenURL = function(url, callback) { callback(url); };
|
||||
|
||||
if (config.lstu) {
|
||||
if (config.lstu[config.lstu.length - 1] !== '/') {
|
||||
config.lstu += '/';
|
||||
}
|
||||
|
||||
shortenURL = function shortenURL(url, callback) {
|
||||
request(config.lstu + 'a', { method: 'POST', form: { lsturl: url, format: 'json' } }, function (err, res, body) {
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
} catch(err) {
|
||||
@ -46,6 +53,7 @@ function shortenURL(url, callback) {
|
||||
callback(body.short);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
var handlers = {
|
||||
|
Loading…
Reference in New Issue
Block a user