Last active
November 1, 2019 03:10
-
-
Save ttseng/6478bd0a84add0e0a0c84f9c034e47d3 to your computer and use it in GitHub Desktop.
Colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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