Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
A
augustctl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
open-source
augustctl
Commits
924633a1
Verified
Commit
924633a1
authored
Aug 27, 2016
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utility method for lock connecitons
parent
9481a901
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
server.js
server.js
+20
-16
No files found.
server.js
View file @
924633a1
...
...
@@ -28,10 +28,22 @@ app.use( morgan( DEBUG ? 'dev' : 'combined' ) );
// Default return arguments
var
ret
=
{
'
status
'
:
-
1
,
'
ret
'
:
''
,
'
msg
'
:
''
};
'
status
'
:
-
1
,
'
ret
'
:
''
,
'
msg
'
:
''
};
// Get lock instance
function
getLockInstance
(
lockName
)
{
var
lock
=
app
.
get
(
'
lock
'
+
lockName
);
if
(
lock
)
{
return
lock
;
}
else
{
clearCaches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
return
false
;
}
}
// Convert named status to integer representation
function
statusStringtoInt
(
status
)
{
...
...
@@ -57,10 +69,8 @@ function clearCaches( lockName ) {
// Reset lock connection
function
disconnectAndClear
(
lockName
)
{
var
lock
=
app
.
get
(
'
lock
'
+
lockName
);
var
lock
=
getLockInstance
(
lockName
);
if
(
!
lock
)
{
clearCaches
(
lockName
);
res
.
sendStatus
(
400
);
return
;
}
...
...
@@ -75,10 +85,8 @@ function disconnectAndClear( lockName ) {
// Endpoint to check lock status
app
.
get
(
'
/api/status/:lock_name
'
,
cache
(
'
15 seconds
'
),
function
(
req
,
res
)
{
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
if
(
!
lock
)
{
clearCaches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
return
;
}
...
...
@@ -113,10 +121,8 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
}
var
lockName
=
req
.
params
.
lock_name
,
lock
=
app
.
get
(
'
lock
'
+
lockName
);
lock
=
getLockInstance
(
lockName
);
if
(
!
lock
)
{
clearCaches
(
lockName
);
res
.
sendStatus
(
400
);
return
;
}
...
...
@@ -157,10 +163,8 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
// Endpoint to disconnect a lock's BLE connections
app
.
get
(
'
/api/disconnect/:lock_name
'
,
function
(
req
,
res
)
{
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
if
(
!
lock
)
{
clearCaches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment