|
|
@@ -305,10 +305,15 @@ class Stream(NilmApp): |
|
|
|
@cherrypy.tools.json_out() |
|
|
|
@exception_to_httperror(NilmDBError, ValueError) |
|
|
|
@cherrypy.tools.CORS_allow(methods = ["PUT"]) |
|
|
|
def insert(self, path, start, end): |
|
|
|
def insert(self, path, start, end, binary = False): |
|
|
|
""" |
|
|
|
Insert new data into the database. Provide textual data |
|
|
|
(matching the path's layout) as a HTTP PUT. |
|
|
|
|
|
|
|
If 'binary' is True, expect raw binary data, rather than lines |
|
|
|
of ASCII-formatted data. Raw binary data is always |
|
|
|
little-endian and matches the database types (including an |
|
|
|
int64 timestamp). |
|
|
|
""" |
|
|
|
# Important that we always read the input before throwing any |
|
|
|
# errors, to keep lengths happy for persistent connections. |
|
|
@@ -316,6 +321,14 @@ class Stream(NilmApp): |
|
|
|
# requests, if we ever want to handle those (issue #1134) |
|
|
|
body = cherrypy.request.body.read() |
|
|
|
|
|
|
|
# Verify content type for binary data |
|
|
|
content_type = cherrypy.request.headers.get('content-type') |
|
|
|
if binary and content_type: |
|
|
|
if content_type != "application/octet-stream": |
|
|
|
raise cherrypy.HTTPError("400", "Content type must be " |
|
|
|
"application/octet-stream for " |
|
|
|
"binary data, not " + content_type) |
|
|
|
|
|
|
|
# Check path and get layout |
|
|
|
if len(self.db.stream_list(path = path)) != 1: |
|
|
|
raise cherrypy.HTTPError("404", "No such stream: " + path) |
|
|
@@ -325,7 +338,7 @@ class Stream(NilmApp): |
|
|
|
|
|
|
|
# Pass the data directly to nilmdb, which will parse it and |
|
|
|
# raise a ValueError if there are any problems. |
|
|
|
self.db.stream_insert(path, start, end, body) |
|
|
|
self.db.stream_insert(path, start, end, body, binary) |
|
|
|
|
|
|
|
# Done |
|
|
|
return |
|
|
|