add web api function for getUrl instead of string in base, use externalAddress optional config key to define external behaviours [#264]

This commit is contained in:
reality 2013-04-12 22:53:45 +00:00
parent d8342f4489
commit 677a820638
6 changed files with 18 additions and 17 deletions

View File

@ -21,14 +21,12 @@ var commands = function(dbot) {
for(var i=0;i<options.length;i++) {
polls[name]['votes'][options[i]] = 0;
}
event.reply(dbot.t('poll_created', {
'name': name,
'description': description,
'url': dbot.t('url', {
'host': dbot.config.web.webHost,
'port': dbot.config.web.webPort,
'path': 'polls/' + name
})
'url': dbot.api.web.getUrl('/poll/' + name)
}));
}
},

View File

@ -33,7 +33,7 @@ var commands = function(dbot){
if(event.params[1]){
var primary = dbot.api.users.resolveUser(event.server, event.params[1]);
if(_.has(dbot.db.profiles[event.server], primary.toLowerCase())){
event.reply("http://"+dbot.config.web.webHost+":"+dbot.config.web.webPort+"/profile/"+event.server+"/"+primary.toLowerCase());
event.reply(dbot.api.web.getUrl("/profile/"+event.server+"/"+primary.toLowerCase());
}
else{
event.reply("No profile found for "+event.params[1]);

View File

@ -71,7 +71,6 @@ var commands = function(dbot) {
},
// Search a given category for some text.
// TODO fix
'~qsearch': function(event) {
var haystack = event.input[1].trim().toLowerCase();
var needle = event.input[2];
@ -202,11 +201,7 @@ var commands = function(dbot) {
_.has(dbot.config.web, 'webPort')) {
event.reply(dbot.t('quote_link', {
'category': key,
'url': dbot.t('url', {
'host': dbot.config.web.webHost,
'port': dbot.config.web.webPort,
'path': 'quotes/' + encodeURIComponent(key)
})
'url': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key))
}));
} else {
event.reply(dbot.t('web_not_configured'));

View File

@ -1,4 +1,5 @@
{
"webHost": "localhost",
"webPort": 8080
"webPort": 8080,
"externalPath": false
}

View File

@ -37,7 +37,17 @@ var webInterface = function(dbot) {
this.onDestroy = function() {
server.close();
}
};
this.api = {
'getUrl': function(path) {
if(this.config.externalPath) {
return this.config.externalPath + '/' + path;
} else {
return 'http://' + this.config.webHost + ':' + port + '/' + path;
}
};
};
};
exports.fetch = function(dbot) {

View File

@ -10,8 +10,5 @@
"es": "No se pudó cargar el módulo: {moduleName}",
"na'vi": "Oeru Oel {moduleName}it sung.",
"cy": "Wedi methu a llwytho modiwl: {moduleName}"
},
"url": {
"en": "http://{host}:{port}/{path}"
}
}