Toggle navigation
Toggle navigation
This project
Loading...
Sign in
digsig
/
digsig-services
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Stefan Huber
2017-03-27 11:23:12 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9ee36ad2bcaeb278234c00c89825ba127f488661
9ee36ad2
1 parent
fc5918a4
api changes
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
40 additions
and
27 deletions
dist/api/node.d.ts
dist/api/node.js
dist/services/repository.d.ts
dist/services/repository.js
dist/services/rest.d.ts
dist/services/rest.js
src/api/node.ts
src/services/repository.ts
src/services/rest.ts
dist/api/node.d.ts
0 → 100644
View file @
9ee36ad
export
interface
Node
{
ip
:
string
;
uuid
:
string
;
couchPort
:
string
;
webPort
:
string
;
}
dist/api/node.js
0 → 100644
View file @
9ee36ad
"use strict"
;
dist/services/repository.d.ts
View file @
9ee36ad
...
...
@@ -6,10 +6,8 @@ export declare class Repository {
protected
device
:
Device
;
protected
_db
:
any
;
protected
_params
:
any
;
protected
_localWebPort
:
number
;
db
:
any
;
params
:
any
;
readonly
localWebPort
:
number
;
constructor
(
rest
:
Rest
,
device
:
Device
);
findById
(
id
:
string
):
Promise
<
any
>
;
findByIds
(
ids
:
Array
<
string
>
):
Promise
<
Array
<
any
>>
;
...
...
dist/services/repository.js
View file @
9ee36ad
...
...
@@ -15,7 +15,6 @@ var Repository = (function () {
function
Repository
(
rest
,
device
)
{
this
.
rest
=
rest
;
this
.
device
=
device
;
this
.
_localWebPort
=
8320
;
}
Object
.
defineProperty
(
Repository
.
prototype
,
"db"
,
{
get
:
function
()
{
...
...
@@ -37,13 +36,6 @@ var Repository = (function () {
enumerable
:
true
,
configurable
:
true
});
Object
.
defineProperty
(
Repository
.
prototype
,
"localWebPort"
,
{
get
:
function
()
{
return
this
.
_localWebPort
;
},
enumerable
:
true
,
configurable
:
true
});
Repository
.
prototype
.
findById
=
function
(
id
)
{
return
this
.
db
.
get
(
id
);
};
...
...
@@ -112,7 +104,7 @@ var Repository = (function () {
_this
.
rest
.
scanEnvironment
(
response
.
local_ips
)
.
then
(
function
(
node
)
{
var
res
=
_this
.
parseUrl
(
response
.
db_url
);
resolve
(
_this
.
prepare
(
res
.
protocol
+
'://'
+
res
.
user
+
':'
+
res
.
pass
+
'@'
+
node
.
IP
+
':'
+
_this
.
localWeb
Port
+
'/'
+
res
.
orig_db_name
));
resolve
(
_this
.
prepare
(
res
.
protocol
+
'://'
+
res
.
user
+
':'
+
res
.
pass
+
'@'
+
node
.
ip
+
':'
+
node
.
couch
Port
+
'/'
+
res
.
orig_db_name
));
}).
catch
(
function
()
{
resolve
(
_this
.
prepare
(
response
.
db_url
));
});
...
...
dist/services/rest.d.ts
View file @
9ee36ad
import
{
Http
}
from
'@angular/http'
;
import
{
DeviceInfo
}
from
'./../api/device-info'
;
import
{
Node
}
from
'./../api/node'
;
export
declare
const
ERROR_CODE_UNAUTHORIZED
:
string
;
export
declare
const
ERROR_CODE_NOT_FOUND
:
string
;
export
declare
const
ERROR_CODE_SERVER_ERROR
:
string
;
export
declare
class
Rest
{
private
http
;
static
localWebPort
:
number
;
static
serviceUrl
:
string
;
constructor
(
http
:
Http
);
prepareDeviceInfo
(
deviceInfo
:
DeviceInfo
,
prefixed
?:
boolean
):
string
;
register
(
registerCode
:
string
,
deviceInfo
:
DeviceInfo
):
Promise
<
any
>
;
heartbeat
(
deviceInfo
:
DeviceInfo
):
Promise
<
any
>
;
scanNode
(
node
:
any
):
Promise
<
any
>
;
scanEnvironment
(
nodes
:
any
[]):
Promise
<
any
>
;
scanNode
(
node
:
any
):
Promise
<
Node
>
;
scanEnvironment
(
nodes
:
any
[]):
Promise
<
Node
>
;
}
...
...
dist/services/rest.js
View file @
9ee36ad
...
...
@@ -92,12 +92,17 @@ var Rest = Rest_1 = (function () {
var
_this
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
node
&&
node
.
IP
)
{
_this
.
http
.
get
(
node
.
IP
+
"/device"
)
_this
.
http
.
get
(
"http://"
+
node
.
IP
+
":"
+
Rest_1
.
localWebPort
+
"/device"
)
.
subscribe
(
function
(
response
)
{
try
{
var
body
=
response
.
json
();
if
(
body
.
device_id
==
node
.
UUID
)
{
resolve
(
body
);
resolve
({
ip
:
node
.
IP
,
uuid
:
body
.
device_id
,
couchPort
:
body
.
couch_port
,
webPort
:
node
.
web_port
});
}
else
{
reject
();
...
...
@@ -135,6 +140,7 @@ var Rest = Rest_1 = (function () {
};
return
Rest
;
}());
Rest
.
localWebPort
=
8320
;
Rest
.
serviceUrl
=
"http://someurl.com"
;
Rest
=
Rest_1
=
__decorate
([
core_1
.
Injectable
(),
...
...
src/api/node.ts
0 → 100644
View file @
9ee36ad
export
interface
Node
{
ip
:
string
;
uuid
:
string
;
couchPort
:
string
;
webPort
:
string
;
}
\ No newline at end of file
src/services/repository.ts
View file @
9ee36ad
...
...
@@ -10,7 +10,6 @@ export class Repository {
protected
_db
:
any
;
protected
_params
:
any
;
protected
_localWebPort
:
number
=
8320
;
get
db
()
{
return
this
.
_db
;
...
...
@@ -28,10 +27,6 @@ export class Repository {
this
.
_params
=
params
;
}
get
localWebPort
()
:
number
{
return
this
.
_localWebPort
;
}
constructor
(
protected
rest
:
Rest
,
protected
device
:
Device
...
...
@@ -104,7 +99,7 @@ export class Repository {
this
.
rest
.
scanEnvironment
(
response
.
local_ips
)
.
then
(
node
=>
{
let
res
=
this
.
parseUrl
(
response
.
db_url
);
resolve
(
this
.
prepare
(
res
.
protocol
+
'://'
+
res
.
user
+
':'
+
res
.
pass
+
'@'
+
node
.
IP
+
':'
+
this
.
localWeb
Port
+
'/'
+
res
.
orig_db_name
));
resolve
(
this
.
prepare
(
res
.
protocol
+
'://'
+
res
.
user
+
':'
+
res
.
pass
+
'@'
+
node
.
ip
+
':'
+
node
.
couch
Port
+
'/'
+
res
.
orig_db_name
));
}).
catch
(()
=>
{
resolve
(
this
.
prepare
(
response
.
db_url
));
});
...
...
src/services/rest.ts
View file @
9ee36ad
import
{
Injectable
}
from
'@angular/core'
;
import
{
Http
,
Response
,
Headers
}
from
'@angular/http'
;
import
{
DeviceInfo
}
from
'./../api/device-info'
;
import
{
Node
}
from
'./../api/node'
;
export
const
ERROR_CODE_UNAUTHORIZED
:
string
=
"unauthorized"
;
export
const
ERROR_CODE_NOT_FOUND
:
string
=
"not-found"
;
...
...
@@ -9,6 +10,7 @@ export const ERROR_CODE_SERVER_ERROR:string = "server-error";
@
Injectable
()
export
class
Rest
{
public
static
localWebPort
:
number
=
8320
;
public
static
serviceUrl
:
string
=
"http://someurl.com"
;
constructor
(
private
http
:
Http
)
{}
...
...
@@ -94,15 +96,20 @@ export class Rest {
});
}
scanNode
(
node
:
any
)
:
Promise
<
any
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
scanNode
(
node
:
any
)
:
Promise
<
Node
>
{
return
new
Promise
<
Node
>
((
resolve
,
reject
)
=>
{
if
(
node
&&
node
.
IP
)
{
this
.
http
.
get
(
node
.
IP
+
"/device"
)
this
.
http
.
get
(
"http://"
+
node
.
IP
+
":"
+
Rest
.
localWebPort
+
"/device"
)
.
subscribe
(
response
=>
{
try
{
let
body
=
response
.
json
();
if
(
body
.
device_id
==
node
.
UUID
)
{
resolve
(
body
);
resolve
({
ip
:
node
.
IP
,
uuid
:
body
.
device_id
,
couchPort
:
body
.
couch_port
,
webPort
:
node
.
web_port
});
}
else
{
reject
();
}
...
...
@@ -118,8 +125,8 @@ export class Rest {
});
}
scanEnvironment
(
nodes
:
any
[])
:
Promise
<
any
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
scanEnvironment
(
nodes
:
any
[])
:
Promise
<
Node
>
{
return
new
Promise
<
Node
>
((
resolve
,
reject
)
=>
{
let
index
=
Math
.
floor
(
Math
.
random
()
*
nodes
.
length
);
let
node
=
nodes
.
splice
(
index
,
1
)[
0
];
this
.
scanNode
(
node
)
...
...
Please
register
or
login
to post a comment