genericity: send any text

This commit is contained in:
Guilhem Saurel 2019-02-13 00:55:24 +01:00
parent 09cb1566bf
commit c54e5da19d
2 changed files with 4 additions and 4 deletions

View file

@ -30,5 +30,5 @@ docker-compose up -d
## Test ## Test
``` ```
curl -d '{"name":"toto", "url":"http://radio.localhost/map/#44", "key": "secret"}' wwm.localhost curl -d '{"text":"new contrib from toto: http://radio.localhost/map/#44", "key": "secret"}' wwm.localhost
``` ```

View file

@ -42,12 +42,12 @@ class WWMBotForwarder(BaseHTTPRequestHandler):
""" """
length = int(self.headers.get('Content-Length')) length = int(self.headers.get('Content-Length'))
data = json.loads(self.rfile.read(length).decode()) data = json.loads(self.rfile.read(length).decode())
status = 'I need a json dict with name, url, key' status = 'I need a json dict with text & key'
if all(key in data for key in ['name', 'url', 'key']): if all(key in data for key in ['text', 'key']):
status = 'wrong key' status = 'wrong key'
if data['key'] == API_KEY: if data['key'] == API_KEY:
status = 'OK' status = 'OK'
self.server.room.send_text(f'Nouvelle demande de {data["name"]}: {data["url"]}') self.server.room.send_text(data['text'])
self.send_response(200 if status == 'OK' else 401) self.send_response(200 if status == 'OK' else 401)
self.send_header('Content-Type', 'application/json') self.send_header('Content-Type', 'application/json')