Mon 21 Jul 22:43:21 CEST 2025
This commit is contained in:
parent
838f6c0e55
commit
a20fff7174
67
js/dos/ext/satelize.js
Normal file
67
js/dos/ext/satelize.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* satelize - v0.1.3
|
||||
*
|
||||
* (c) 2013 Julien VALERY https://github.com/darul75/satelize, 2018-2020 modfied by bLAB Dr. Stefan Bosse
|
||||
*
|
||||
* Usage: satelize(ip:string|undefined,function (err,info))
|
||||
*
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
|
||||
var http=Require("http"),
|
||||
serviceHost="ip-api.com",
|
||||
servicePort=80,
|
||||
servicePath="/json",
|
||||
serviceJSONP="";
|
||||
|
||||
function Satelize(options){
|
||||
this.init()
|
||||
}
|
||||
|
||||
Satelize.prototype.init=function(options){
|
||||
return this
|
||||
}
|
||||
|
||||
Satelize.prototype.satelize=function(a,b){
|
||||
var c=(a.ip?"/"+a.ip:"")+(a.JSONP?serviceJSONP:""),
|
||||
d=a.timeout||1e3,
|
||||
h=a.url||a.host||serviceHost,
|
||||
p=a.port||servicePort,
|
||||
e,
|
||||
f;
|
||||
if (!http) return b('ENOTSUPPORTED',null);
|
||||
if (!http.xhr && http.request) {
|
||||
// server
|
||||
e={hostname:h,path:servicePath+c,method:"GET",port:p};
|
||||
f=http.request(e,function(a){
|
||||
a.setEncoding("utf8");
|
||||
var c="";
|
||||
a.on("data",function(a){c+=a}),
|
||||
a.on("end",function(){
|
||||
try {
|
||||
return b(null,JSON.parse(c));
|
||||
} catch (err) {
|
||||
b(err.toString()+', '+e.hostname+':'+e.port);
|
||||
}
|
||||
})
|
||||
});
|
||||
return f.on("error",function(a){return b(a)}),
|
||||
f.setTimeout(d,function(){return b(new Error("timeout"))}),
|
||||
f.end(),this;
|
||||
} else {
|
||||
// Browser
|
||||
e={uri:a.url?a.url:(a.proto?a.proto:'http')+'://'+h+':'+p+servicePath+c,
|
||||
method:"GET",
|
||||
headers:{}};
|
||||
console.log(e);
|
||||
http.request(e,function(err,xhr,body){
|
||||
if (err) return b(err);
|
||||
else try { b(null,JSON.parse(body)); } catch (err) { b(err.toString()+', '+e.uri) }
|
||||
})
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
var sat = new Satelize
|
||||
module.exports=sat;
|
Loading…
Reference in New Issue
Block a user