Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
augustctl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
augustctl
Commits
924633a1
Verified
Commit
924633a1
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Utility method for lock connecitons
parent
9481a901
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.js
+20
-16
20 additions, 16 deletions
server.js
with
20 additions
and
16 deletions
server.js
+
20
−
16
View file @
924633a1
...
@@ -28,10 +28,22 @@ app.use( morgan( DEBUG ? 'dev' : 'combined' ) );
...
@@ -28,10 +28,22 @@ app.use( morgan( DEBUG ? 'dev' : 'combined' ) );
// Default return arguments
// Default return arguments
var
ret
=
{
var
ret
=
{
'
status
'
:
-
1
,
'
status
'
:
-
1
,
'
ret
'
:
''
,
'
ret
'
:
''
,
'
msg
'
:
''
'
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
// Convert named status to integer representation
function
statusStringtoInt
(
status
)
{
function
statusStringtoInt
(
status
)
{
...
@@ -57,10 +69,8 @@ function clearCaches( lockName ) {
...
@@ -57,10 +69,8 @@ function clearCaches( lockName ) {
// Reset lock connection
// Reset lock connection
function
disconnectAndClear
(
lockName
)
{
function
disconnectAndClear
(
lockName
)
{
var
lock
=
app
.
get
(
'
lock
'
+
lockName
);
var
lock
=
getLockInstance
(
lockName
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clearCaches
(
lockName
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
@@ -75,10 +85,8 @@ function disconnectAndClear( lockName ) {
...
@@ -75,10 +85,8 @@ function disconnectAndClear( lockName ) {
// Endpoint to check lock status
// Endpoint to check lock status
app
.
get
(
'
/api/status/:lock_name
'
,
cache
(
'
15 seconds
'
),
function
(
req
,
res
)
{
app
.
get
(
'
/api/status/:lock_name
'
,
cache
(
'
15 seconds
'
),
function
(
req
,
res
)
{
// Parse allowed request arguments
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clearCaches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
@@ -113,10 +121,8 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
...
@@ -113,10 +121,8 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
}
}
var
lockName
=
req
.
params
.
lock_name
,
var
lockName
=
req
.
params
.
lock_name
,
lock
=
app
.
get
(
'
lock
'
+
lockName
);
lock
=
getLockInstance
(
lockName
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clearCaches
(
lockName
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
@@ -157,10 +163,8 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '5 seconds' ), func
...
@@ -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
// Endpoint to disconnect a lock's BLE connections
app
.
get
(
'
/api/disconnect/:lock_name
'
,
function
(
req
,
res
)
{
app
.
get
(
'
/api/disconnect/:lock_name
'
,
function
(
req
,
res
)
{
// Parse allowed request arguments
// Parse allowed request arguments
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
if
(
!
lock
)
{
if
(
!
lock
)
{
clearCaches
(
req
.
params
.
lock_name
);
res
.
sendStatus
(
400
);
return
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment