picture api ready
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
SensorData = new Mongo.Collection("sensorData");
|
||||
ControllerState = new Mongo.Collection("controller_states");
|
||||
Picture = new Mongo.Collection("pictures");
|
||||
|
||||
BIN
app/public/images/noImage.png
Normal file
BIN
app/public/images/noImage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
@@ -10,7 +10,7 @@ Api.addRoute('sensorData', {
|
||||
}, {
|
||||
post: function() {
|
||||
reactToSensorData(this.bodyParams);
|
||||
SensorData.insert({
|
||||
var sensorObject = {
|
||||
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||
tankLevel0: this.bodyParams.tankLevel0,
|
||||
@@ -24,7 +24,8 @@ Api.addRoute('sensorData', {
|
||||
owner: this.bodyParams.owner,
|
||||
controllerId: this.bodyParams.controllerId,
|
||||
created_at: new Date()
|
||||
});
|
||||
};
|
||||
SensorData.insert(sensorObject);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
@@ -116,10 +117,50 @@ Api.addRoute('state/:id', {
|
||||
}
|
||||
});
|
||||
|
||||
Api.addRoute('picture/:id', {
|
||||
authRequired: false
|
||||
}, {
|
||||
post: function() {
|
||||
console.log("setting picture", this.bodyParams);
|
||||
return Picture.upsert({
|
||||
controller_id: this.urlParams.id
|
||||
}, {
|
||||
'$set': {
|
||||
'picture_base64': this.bodyParams.picture_base64,
|
||||
'time': new Date()
|
||||
}
|
||||
});
|
||||
},
|
||||
get: function() {
|
||||
var id = this.urlParams.id;
|
||||
var res = this.response;
|
||||
var picture_src = "/images/noImage.png";
|
||||
var pictureEntry = Picture.findOne({
|
||||
controller_id: id
|
||||
});
|
||||
if (pictureEntry) {
|
||||
var imageData = pictureEntry.picture_base64;
|
||||
picture_src = "data:image/jpeg;charset=utf-8;base64," + imageData;
|
||||
}
|
||||
return {
|
||||
picture: picture_src
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function base64_to_buffer(base64string) {
|
||||
var buf;
|
||||
if (typeof Buffer.from === "function") {
|
||||
buf = Buffer.from(base64string, 'base64');
|
||||
} else {
|
||||
buf = new Buffer(base64string, 'base64');
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function stateOrDefault(id) {
|
||||
var stateEntry = ControllerState.findOne({
|
||||
controller_id: id,
|
||||
controller_id: id
|
||||
});
|
||||
|
||||
if (stateEntry === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user