Skip to content

Instantly share code, notes, and snippets.

@ttseng
Last active November 1, 2019 03:10
Show Gist options
  • Save ttseng/6478bd0a84add0e0a0c84f9c034e47d3 to your computer and use it in GitHub Desktop.
Save ttseng/6478bd0a84add0e0a0c84f9c034e47d3 to your computer and use it in GitHub Desktop.
Colors
app.post('/setColor', function(request, response){
console.log(request.body);
colorDb.run(`INSERT INTO Color VALUES ("${request.body.color}", "${Date.now()}")`, (error) => {
if(error){
response.send({message: 'error!'});
}else{
console.log('added color');
response.send({message: 'success'});
}
});
});
app.get('/getColor', function(request, response) {
colorDb.all('SELECT * from COLOR ORDER BY date DESC LIMIT 1', function(err, row){
if(err) console.log(err);
if(row[0] && row[0].color){
const color = row[0].color;
// create an array from the hex color
const rgb = hexRgb(color);
response.send(JSON.stringify([rgb.red, rgb.green, rgb.blue]));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment