mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update uriloader.js
This commit is contained in:
parent
aaacd28dbe
commit
0c36e8cf61
64
uriloader.js
64
uriloader.js
|
@ -7,24 +7,15 @@
|
|||
var SHELL = require("lib/shell");
|
||||
|
||||
return {
|
||||
parseQuery: function(queryString) {
|
||||
var query = {};
|
||||
var pairs = (queryString.substring(0, 1) === '?' ? queryString.substring(1) : queryString).split('&');
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i].split('=');
|
||||
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
||||
}
|
||||
return query;
|
||||
},
|
||||
main: function(args) {
|
||||
var uri = args[0];
|
||||
var pos = uri.indexOf(':///');
|
||||
var pos = uri.indexOf(":///");
|
||||
if(pos < 0) {
|
||||
console.log("Not vaild URI");
|
||||
console.log("Not vaild URI scheme");
|
||||
} else {
|
||||
var commandOptions = [],
|
||||
var cmd = [],
|
||||
queryString = uri.substring(pos + 4),
|
||||
query = this.parseQuery(queryString);
|
||||
query = this.parseQueryString(queryString);
|
||||
|
||||
if(!query.application) {
|
||||
query.application = "";
|
||||
|
@ -32,39 +23,62 @@ return {
|
|||
|
||||
switch(query.application) {
|
||||
case "app":
|
||||
commandOptions.push("app.hta");
|
||||
cmd.push(["app.hta"].concat(args));
|
||||
break;
|
||||
case "mscalc":
|
||||
commandOptions.push("calc");
|
||||
cmd.push("calc.exe");
|
||||
break;
|
||||
case "msie":
|
||||
commandOptions.push("\"%PROGRAMFILES%\\Internet Explorer\\iexplore.exe\"");
|
||||
commandOptions.push("https://github.com/gnh1201/welsonjs");
|
||||
cmd.push("%PROGRAMFILES%\\Internet Explorer\\iexplore.exe");
|
||||
cmd.push("https://github.com/gnh1201/welsonjs");
|
||||
break;
|
||||
case "msexcel":
|
||||
commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\EXCEL.EXE\"");
|
||||
cmd.push("%PROGRAMFILES%\\Microsoft Office\\Office15\\EXCEL.EXE");
|
||||
break;
|
||||
case "mspowerpoint":
|
||||
commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\POWERPNT.EXE\"");
|
||||
cmd.push("%PROGRAMFILES%\\Microsoft Office\\Office15\\POWERPNT.EXE");
|
||||
break;
|
||||
case "msword":
|
||||
commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\WINWORD.EXE\"");
|
||||
cmd.push("%PROGRAMFILES%\\Microsoft Office\\Office15\\WINWORD.EXE");
|
||||
break;
|
||||
case "msaccess":
|
||||
commandOptions.push("\"%PROGRAMFILES%\\Microsoft Office\\Office15\\MSACCESS.EXE\"");
|
||||
cmd.push("%PROGRAMFILES%\\Microsoft Office\\Office15\\MSACCESS.EXE");
|
||||
break;
|
||||
dafault:
|
||||
console.log("Unknown application");
|
||||
break;
|
||||
}
|
||||
|
||||
if(typeof(query.argument) !== "undefined") {
|
||||
commandOptions.push(query.argument);
|
||||
if(typeof(query.args) !== "undefined") {
|
||||
cmd.push(query.args);
|
||||
}
|
||||
|
||||
SHELL.run(commandOptions.join(' '));
|
||||
SHELL.run(cmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
parseQueryString: function(queryString) {
|
||||
var query = {};
|
||||
var pairs = (queryString.substring(0, 1) === '?' ? queryString.substring(1) : queryString).split('&');
|
||||
for (var i in pairs) {
|
||||
var pair = pairs[i].split('=');
|
||||
var _k = decodeURIComponent(pair[0]);
|
||||
var _v = decodeURIComponent(pair[1] || '');
|
||||
var path = _k.split('[').map(function(s) {
|
||||
return (s.indexOf(']') < 0 ? s : s.substring(0, s.length -1));
|
||||
}).join('/');
|
||||
|
||||
if(path in query) {
|
||||
if (Array.isArray(query[path])) {
|
||||
query[path].push(_v);
|
||||
} else {
|
||||
query[path] = [query[path], _v];
|
||||
}
|
||||
} else {
|
||||
query[path] = _v;
|
||||
}
|
||||
}
|
||||
return query;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user